[Rd] Inconsistent behaviour of is.vector? (PR#1052)
J.C.Rougier@durham.ac.uk
J.C.Rougier@durham.ac.uk
Tue, 14 Aug 2001 10:09:18 +0200 (MET DST)
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? 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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._