[Rd] Drop single-dimensional array

Tony Plate tplate at acm.org
Fri Sep 10 02:18:00 CEST 2010


  On 9/9/2010 10:54 AM, William Dunlap wrote:
>> -----Original Message-----
>> From: r-devel-bounces at r-project.org
>> [mailto:r-devel-bounces at r-project.org] On Behalf Of Arni Magnusson
>> Sent: Wednesday, September 08, 2010 11:55 AM
>> To: r-devel at r-project.org
>> Cc: Simon Urbanek
>> Subject: [Rd] Drop single-dimensional array
>>
>> Hi Simon, thank you for the concise reply.
>>
>> Do you mean the reported behavior of drop() is not a bug?
>>
>> It looks like a borderline bug to me (see below), but I'm not
>> the judge of
>> that. If this is the intended behavior and serves an actual
>> purpose, then
>> that could be explicitly documented in a \note{} on the help page.
>>
>> Such a note would slightly reduce the surprise of users
>> running into this
>> behavior.
>>
>> This is related to the oddity that one-dimensional arrays are:
>>
>>     array(month.abb, dim=c(1,1,12))  # array
>>     array(month.abb, dim=c(1,12))    # matrix
>>     array(month.abb, dim=12)         # array
>>
>> Firstly, one would expect the pattern to be
>> array-matrix-vector.
> I would expect the array() constructor function to return
> something of class array.  (I guess matrix is acceptable
> because it inherits from array).
>
> One dimensional arrays and vectors act very similarly
> when used in R code.  E.g., names(array1d) gives you
> the same thing as dimnames(array1d)[[1]].  Accessing
> them from C code probably shows more differences.
> Are there features beyond drop's behavior that are
> causing you to be concerned about differences between
> the 2 types?
>
> drop(x) and x[..., drop=TRUE] have always bugged me
> because you couldn't control which dimensions got
> dropped.  E.g., if you have a n by 2 by 3 array
> and want to get the 3rd n by 2 slice of it as a matrix
> you can do
>     array[,,3,drop=TRUE]
> except when n==1.  It would be nice to be able to say
> "drop the 3rd dimension, throwing an error if that
> dimension is not 1".
That always bugged me too.  The 'abind' package has an 'adrop()' function with this behavior, and I was just working on an enhancement of it that would make it able to convert 1-d arrays to named vectors when this thread started.

-- Tony Plate

> Bill Dunlap
> Spotfire, TIBCO Software
> wdunlap tibco.com



More information about the R-devel mailing list