[Rd] Testing for vectors

Hadley Wickham h@wickh@m @ending from gm@il@com
Sat Jul 7 20:20:40 CEST 2018

On Sat, Jul 7, 2018 at 12:54 PM, Duncan Murdoch
<murdoch.duncan using gmail.com> wrote:
> 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.)

I was thinking primarily of completing the set of is.matrix() and
is.array(), or generally, how do you say: is `x` a 1d dimensional

(I don't have any feel for whether the check should be is.null(dim(x))
vs. length(dim(x)) <= 1)


More information about the R-devel mailing list