R-alpha: What should is.vector do?

Ross Ihaka ihaka@stat.auckland.ac.nz
Mon, 7 Apr 1997 08:58:11 +1200 (NZST)


[ Consumer warning: This is a little technical ... ]

I have been pondering the question

		What should is.vector do?

Martin has raised this a number of times.  I ran a few tests 
in S and got the following results.

	S> is.vector(list(1,2,3))
	[1] T
	S> is.vector(expression(a+b))
	[1] T
	S> is.vector(as.name("x"))
	[1] T  
	S> is.vector(NULL)
	[1] T
	S> x <- 1:5
	S> is.vector(x)
	[1] T
	S> names(x) <- letters[1:5] 
	S> is.vector(x)
	[1] F

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.
	
Internally in R, we have a predicate isVector() which returns
true if its argument has one of the storage modes "logical",
"factor", "ordered", "integer", "real", "complex" and "character".
This is useful because these are the types which can be subscripted 
(without using CAR and CDR).  We almost certainly need an external
version of this predicate.  I suppose that it could be called	 
is.vector.mode(x).

Another reasonable definition of "vector" is !is.array(x).
or possibly "isVector(x) == 1 && !is.array(x)

What complicates things is that there is a second argument
which specifies a mode for the vector.  In S, it is possible to
have calls like

	is.vector(x, "list")
	is.vector(x, "language")

We have gone some way down the road to mimicing this behaviour,
but it really doesn't fit naturally into the R model.

Looking at our own code base, I see that "is.vector" is used only
in the "data.entry" functions, (and I think I need to check that
code carefully).  We seem to use the predicates

	is.list(x)
	is.language(x)

etc in preference to the above.

Anyway, can we communally come to (reasonably) firm conclusion about
what is.vector should do?  I'm prepared to implement almost anything,
but I'm rather confused about exactly what is.vector should do.
	Ross
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
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
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-