From murdoch@dunc@n @ending from gm@il@com  Sat Jul  7 19:54:14 2018
From: murdoch@dunc@n @ending from gm@il@com (Duncan Murdoch)
Date: Sat, 7 Jul 2018 13:54:14 -0400
Subject: [Rd] Testing for vectors
In-Reply-To: <CABdHhvF5gqJt3kDj-QuU92BWPiLWwGugxnNzOfHOHo9tp_AigA@mail.gmail.com>
References: <CABdHhvF5gqJt3kDj-QuU92BWPiLWwGugxnNzOfHOHo9tp_AigA@mail.gmail.com>
Message-ID: <2b0f1462-99d1-d908-5ea6-e9d21be02d11@gmail.com>

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



[Rd] Testing for vectors
Duncan Murdoch