[Rd] Testing for vectors

Duncan Murdoch murdoch@dunc@n @ending from gm@il@com
Sat Jul 7 19:54:14 CEST 2018


On 07/07/2018 1:20 PM, Hadley Wickham wrote:
> Hi all,
> 
> Is there are base function that I've missed that tests if an object is
> a vector in the dimensionality sense, rather than the data structure
> sense? i.e. something that checks is.null(dim(x)) ?
> 
> is.vector() is trivially disqualified since it also checks for the
> presence of non-names attributes:
> 
> x <- factor(c("a", "a", "b"))
> is.vector(x)
> #> [1] FALSE
> 
> is.null(dim(x))
> #> [1] TRUE
> 

I don't know of one.  I can't think of nontrivial cases where that 
distinction matters; do you know of any where base functions act 
differently on vectors and 1D arrays?  (A trivial example is that 
dimnames(x) gives different results for a named vector and an array with 
dimnames.)

Duncan Murdoch



More information about the R-devel mailing list