[Rd] Inconsistent behaviour of is.vector? (PR#1052)

Kurt Hornik Kurt.Hornik@ci.tuwien.ac.at
Tue, 14 Aug 2001 19:36:26 +0200


>>>>> Peter Dalgaard BSA writes:

> [R-bugs snipped from recipients]

> ripley@stats.ox.ac.uk writes:

>> R appears to allow names as attributes but nothing else, but does not
>> document this (except in the source code).  Anyone want to explain why R
>> is incompatible with S?  And why as.vector and is.vector are inconsistent?
>> (Note that the isas tests do not pick this up.)

> It was discussed during 1997 and 1998... Ross, Thomas, Kurt, and
> Martin seem to have been involved at some point. I'm not up to a full
> reconstruction of the discussion just now, though. One of the earliest
> cases is in this note from Thomas on the R-alpha mailing list:

I only vaguely recall this.  Note however that this is in the FAQ:

   * Named vectors are considered vectors in R but not in S (e.g.,
     `is.vector(c(a = 1:3))' returns `FALSE' in S and `TRUE' in R).

I assume that way back then I argued that it was silly that is.vector
gave FALSE for c(a = 1) and TRUE for c(1).  I think my understanding
would now be different: I would think that as.vector/is.vector should
match what the `generator' vector() does, and that cannot set names.
Otoh it cannot really set data either ...

Just in case someone brings this one up as well: we also have a diff in
is.matrix on a data frame.  Splus 6 still has

> is.matrix(data.frame(x = 1:3))
[1] T

and in fact is.matrix <- function(x) length(dim(x)) == 2, but I am
strongly against that: I still think that

	if as.foo(x) is different from x then is.foo(x) must be false.

And that also `proves' that is.vector is wrong, as

R> x <- c(a = 1)
R> x
a 
1 
R> as.vector(x)
[1] 1
R> is.vector(x)
[1] TRUE

-k

> (excerpted)
> ----
> On Mon, 7 Apr 1997, Ross Ihaka wrote:
>> What should is.vector do?
>> 
> <snip> 
>> Essentially, everything in S is a vector unless it has attributes.
>> This is utterly unreasonable!  Why should something stop being a
>> vector because it has a names attribute attached.

> There is method to this.  Something is a vector in S if as.vector() has 
> no effect on it. This includes functions but excludes matrices, vectors 
> with names, and data.frames.  You might then ask why as.vector() works 
> the way it does and I would have no sensible explanation. A particularly 
> bizarre example is
S> is.vector(lm)
> T
S> is.vector(lm(y~x)$coef)
> F
> i.e., the lm() function is a vector but the coefficient vector isn't.
> ----
> There was also some discussion in December 1998, between Kurt and
> Martin, but I cannot see how it got resolved.

> (I seem to remember that we had as.vector retaining names for a while,
> but got burned by package porting(?). Very early versions of R had
> is.vector returning true for anything that could be subscripted,
> including matrices.) 

> BTW: My list archives seem to go further back than the "official"
> ones. Do we want to do anything about that? Unfortunately they are in
> Gnus's mail directory format and have been respooled so they are
> slightly out of numerical order.

> -- 
>    O__  ---- Peter Dalgaard             Blegdamsvej 3  
>   c/ /'_ --- Dept. of Biostatistics     2200 Cph. N   
>  (*) \(*) -- University of Copenhagen   Denmark      Ph: (+45) 35327918
> ~~~~~~~~~~ - (p.dalgaard@biostat.ku.dk)             FAX: (+45) 35327907
> -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
> r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
> Send "info", "help", or "[un]subscribe"
> (in the "body", not the subject !)  To: r-devel-request@stat.math.ethz.ch
> _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-devel-request@stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._