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

ripley@stats.ox.ac.uk ripley@stats.ox.ac.uk
Tue, 14 Aug 2001 10:43:26 +0200 (MET DST)


This seems intentional.  as.vector(x) changes x, and is.vector should be a
test of no change.  It is in S:

>From S-PLUS 3.4:

       is.vector returns TRUE if x is a simple object of the mode
       specified, and FALSE otherwise.  If the mode is "any", any
       simple object will match,  that  is,  an  object  with  no
       attributes.   Note  that  a  list is typically a vector in
       this sense.

Note the `simple' in there.

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.)

This is a documentation bug, at least.


On Tue, 14 Aug 2001 J.C.Rougier@durham.ac.uk wrote:

> Hi everyone,
>
> I have noticed that is.vector returns FALSE if I attach
> attributes:
>
> > x <- c(a = 1, b = 2)
> > attributes(x)
> $names
> [1] "a" "b"
>
> > is.vector(x)
> [1] TRUE
> > attr(x, "fred") <- "happy"
> > attributes(x)
> $names
> [1] "a" "b"
>
> $fred
> [1] "happy"
>
> > is.vector(x)
> [1] FALSE
>
> This seems inconsistent to me, as "names" is itself an attribute
> yet this does negate is.vector.  As the original x is clearly a
> vector, albeit one with names, wouldn't it be consistent to allow
> any attributes?

Well, dim is an attribute, so you want an array to be a vector?

> This appears to be the case for is.matrix ...
>
> > x <- matrix(1:4, 2, 2)
> > is.matrix(x)
> [1] TRUE
> > attributes(x)
> $dim
> [1] 2 2
> > attr(x, "fred") <- "happy"
> > x
>      [,1] [,2]
> [1,]    1    3
> [2,]    2    4
> attr(,"fred")
> [1] "happy"
> > is.matrix(x)
> [1] TRUE
>
> Cheers, Jonathan.
>
> --please do not edit the information below--
>
> Version:
>  platform = i686-pc-linux-gnu
>  arch = i686
>  os = linux-gnu
>  system = i686, linux-gnu
>  status = Patched
>  major = 1
>  minor = 3.0
>  year = 2001
>  month = 06
>  day = 27
>  language = R
>
> Search Path:
>  .GlobalEnv, Autoloads, package:base
>
> -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
> 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
> _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
>

-- 
Brian D. Ripley,                  ripley@stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272860 (secr)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595


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