From hb at stat.berkeley.edu  Mon Jan 12 21:43:16 2009
From: hb at stat.berkeley.edu (Henrik Bengtsson)
Date: Mon, 12 Jan 2009 12:43:16 -0800
Subject: [Rd] x <- 1:2; dim(x) <- 2? A vector or not?
Message-ID: <59d7961d0901121243j6c5c0fcn5836d94a90666623@mail.gmail.com>

Ran into the follow intermediate case in an external package (w/
recent R v2.8.1 patched and R v2.9.0 devel):

> x <- 1:2
> dim(x) <- 2
> dim(x)
[1] 2
> x
[1] 1 2
> str(x)
 int [, 1:2] 1 2
> nrow(x)
[1] 2
> ncol(x)
[1] NA
> is.vector(x)
[1] FALSE
> is.matrix(x)
[1] FALSE
> is.array(x)
[1] TRUE
> x[1]
[1] 1
> x[,1]
Error in x[, 1] : incorrect number of dimensions
> x[1,]
Error in x[1, ] : incorrect number of dimensions

Is str() treating single-dimension arrays incorrectly?

What does it mean to have a single dimension this way?  Should it
equal a vector?  I am aware of "is.vector returns FALSE if x has any
attributes except names".

/Henrik



[Rd] x <- 1:2; dim(x) <- 2? A vector or not?
Henrik Bengtsson