From tplate at blackmesacapital.com  Fri Jan 26 19:47:18 2007
From: tplate at blackmesacapital.com (Tony Plate)
Date: Fri, 26 Jan 2007 11:47:18 -0700
Subject: [Rd] "[" operator and indexing ambiguity
In-Reply-To: <43ec92880701260755o7cd9cc8el32c6418066233be2@mail.gmail.com>
References: <43ec92880701260755o7cd9cc8el32c6418066233be2@mail.gmail.com>
Message-ID: <45BA4CB6.6020008@blackmesacapital.com>

You can find this info using the function nargs().  I've used this with 
S3 classes, and as far as I know it should work with S4 classes too. 
See ?nargs for examples.

-- Tony Plate

Bradley Buchsbaum wrote:
> Hi,
> 
> I am working on writing some S4 classes that represent
> multidimensional (brain) image data.  I would like these classes to
> support standard array indexing. I have been studying the Matrix and
> EBImage (http://www.bioconductor.org/packages/1.9/bioc/html/EBImage.html)
> packages to see how this is done.
> 
> When using objects of the "array" class directly, R distinguishes
> between the calls:
> 
> x[i,,] and x[i]
> 
> with the former returning a 2D array of values and the latter
> returning a single value.  The question I have is whether this same
> behavior can be simulated in classes that do not inherit from the
> "array" class directly? (See below for a snippet from the EBImage
> package which suggests that it cannot).
> 
> My guess is that native array indexing is making use of the
> information provided by the commas, and this is unavailable to user
> implemented class methods?
> 
> thanks,
> 
> Brad Buchsbaum
> 
> 
> 
> # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
> setMethod("[", signature(x = "Image", i = "numeric", j = "missing"),
>     function(x, i, j, k, ..., drop) {
>         if (missing(k)) {
>             warning("using index [int], cannot distinguish from
> [int,,ANY], use [int,1:dim(x)[2],ANY] otherwise")
>             tmp = x at .Data[i, drop = FALSE]
>         }
>         else {
>             tmp = x at .Data[i, , k, drop = FALSE]
>         }
>         ...
> }
> 
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>



[Rd] "[" operator and indexing ambiguity
Tony Plate