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

Peter Dalgaard BSA p.dalgaard@biostat.ku.dk
14 Aug 2001 12:45:04 +0200


[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:

(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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._