R-alpha: is.vector(.., mode=..) bug (old)

Martin Maechler Martin Maechler <maechler@stat.math.ethz.ch>
Mon, 15 Sep 1997 10:29:37 +0200


It is clear, I think, that
	is.vector(o, mode = "any")
should be  TRUE  whenever any of
	is.vector(o, mode = "<something>")
is TRUE.

This is not yet the case, however, see below.

Consider the following examples  which should be self-explaining.
Besides the above bug, they also show you that -- for S compatibility --
the  mode argument should really use strings as returned by 'mode(.)';
Currently it uses strings as returned by 'typeof(.)',
 see the definition of mode (written in R) which uses typeof(.) [among others].

[[and I've added the following useful EXAMPLE to the  man page of 'mode' 
	 src/library/base/man/mode :

     cex3 <- c("1","1:1","1i","list(1)","args","lm","formals(lm)[[2]]","y~x")
     lex3 <- sapply(cex3, function(x) eval(parse(text=x)))
     mex3 <- t(sapply(lex3, function(x) c(typeof(x), storage.mode(x), mode(x))))
     dimnames(mex3) <- list(cex3, c("typeof(.)","mode(.)","storage.mode(.)"))
     mex3

]]


## Here is my test code revealing the  is.vector(..) problems :

### Ex. 1  --- call ---
cl <- call("lm",y~x)
is.call(cl)# TRUE
mode(cl)  # "call" (S & R);	#__R:  typeof(cl) == "language"

is.vector(cl, mode = "any")      #R: FALSE, S: TRUE
is.vector(cl, mode = "call")     #R: FALSE  S: TRUE
is.vector(cl, mode = "language") #R: TRUE   S: FALSE

### Ex. 2  --- symbol ---
fo <- formula( y ~ x )
mode(fo)  # "call" (S & R)	#__R: typeof(fo) == "language"
is.call(fo)# TRUE  (S & R)
is.name(fo)# FALSE (S & R)

fo1 <- fo[1][[1]]
fo1 # `~'
mode(fo1)  # "name" (S & R)	#__R: typeof(fo1) == "symbol"
is.call(fo1)# FALSE (S & R)
is.name(fo1)# TRUE  (S & R)

is.vector(fo1, mode = "any")    #R: FALSE, S: TRUE
is.vector(fo1, mode = "name")   #R: FALSE, S: TRUE
is.vector(fo1, mode = "symbol") #R: TRUE,  S: FALSE

-----
Martin
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
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
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-