[Rd] array subsetting of S4 object that inherits from "array"

Bradley Buchsbaum bbuchsbaum at berkeley.edu
Fri Mar 6 03:16:40 CET 2009


Hi,

I have an S4 class that inherits from "array" but does not add generic
implementations of the "[" method.

A simplified example is:

setClass("fooarray", contains="array")

If I create a "fooarray" object and subset it with a one-dimensional
index vector, the return value is of class "fooarray". Other variants
(see below), however, return primitive values consistent with
"ordinary" array subsetting.

x <- new("fooarray", array(0,c(10,10,10)))

class(x[1,1,1])        # prints "numeric"
class(x[1,,])           # prints "matrix"
class(x[1])             #  prints "fooarray"
class(x[1:10])        #  prints "fooarray"


This behavior seems to have been introduced in R2.8.1 as I have not
encountered it before. I tested it on R.2.7.0 and confirmed that
class(x[1]) returned "numeric".

In my case, the desired behavior is for array subsetting in all cases
to return primitive data structures, so if there is a way to override
the new behavior I would opt for that.

Regards,

Brad Buchsbaum

R version 2.8.1 (2008-12-22)
i386-pc-mingw32

locale:
LC_COLLATE=English_United States.1252;LC_CTYPE=English_United
States.1252;LC_MONETARY=English_United
States.1252;LC_NUMERIC=C;LC_TIME=English_United States.1252

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base



-- 
Bradley R. Buchsbaum
Rotman Research Institute
3560 Bathurst St.
Toronto, ON Canada M6A 2E1
email: bbuchsbaum at rotman-baycrest.on.ca



More information about the R-devel mailing list