From h@wickh@m @ending from gm@il@com  Sat Jul  7 20:20:40 2018
From: h@wickh@m @ending from gm@il@com (Hadley Wickham)
Date: Sat, 7 Jul 2018 13:20:40 -0500
Subject: [Rd] Testing for vectors
In-Reply-To: <2b0f1462-99d1-d908-5ea6-e9d21be02d11@gmail.com>
References: <CABdHhvF5gqJt3kDj-QuU92BWPiLWwGugxnNzOfHOHo9tp_AigA@mail.gmail.com>
 <2b0f1462-99d1-d908-5ea6-e9d21be02d11@gmail.com>
Message-ID: <CABdHhvHuqb82RjNwD4US_oD1pEXLdc2C3YRYpCaV7QTYhUVB9g@mail.gmail.com>

On Sat, Jul 7, 2018 at 12:54 PM, Duncan Murdoch
<murdoch.duncan at 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
thing?

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

Hadley
-- 
http://hadley.nz



[Rd] Testing for vectors
Hadley Wickham