From: Daniel Murphy <chiefmurphy_at_gmail.com>

Date: Wed, 21 Jul 2010 09:06:43 -0700

R-devel_at_r-project.org mailing list

https://stat.ethz.ch/mailman/listinfo/r-devel Received on Wed 21 Jul 2010 - 16:08:41 GMT

Date: Wed, 21 Jul 2010 09:06:43 -0700

Thanks, John. Enjoy Gaithersburg!

On Wed, Jul 21, 2010 at 8:58 AM, John Chambers <jmc_at_r-project.org> wrote:

> There does indeed seem to be a bug in the C code that implements

*> callNextMethod, with the effect of adding a spurious index to calls to the
**> primitive `[` code with more than 2 subscripts.
**>
**> The message "incorrect number of dimensions" is telling the truth, the
**> primitive code gets 4 subscripts instead of 3 (note the "x[i = i, j = j,
**> NULL, ...]" in the error message).
**>
**> Given the time of year, meetings, and the obscurity of this piece of code,
**> the bug won't likely be fixed soon, so any workaround that avoids the use of
**> callNextMethod on `[` with 3 or more subscripts is a good idea.
**>
**>
**> On 7/20/10 1:41 PM, Daniel Murphy wrote:
**>
**>> I have a class that extends array and my method for "[" stops with an
**>> error:
**>>
**>> setClass("A", contains="array")
**>>>
**>> [1] "A"
**>>
**>>> setMethod("[", "A", function(x, i, j, ..., drop = TRUE) new("A",
**>>>
**>> callNextMethod()))
**>> [1] "["
**>>
**>>> a<-new("A",array(1:12,c(4,3,1)))
**>>> a
**>>>
**>> An object of class "A"
**>> , , 1
**>>
**>> [,1] [,2] [,3]
**>> [1,] 1 5 9
**>> [2,] 2 6 10
**>> [3,] 3 7 11
**>> [4,] 4 8 12
**>>
**>> a[1:2,2:3,1]
**>>>
**>> Error in x[i = i, j = j, NULL, ...] : incorrect number of dimensions
**>> Error in callNextMethod() : error in evaluating a 'primitive' next method
**>>
**>>>
**>>>
**>> A similar error does not occur when extending a matrix:
**>>
**>>> setClass("M", contains="matrix")
**>>>
**>> [1] "M"
**>>
**>>> setMethod("[", "M", function(x, i, j, ..., drop = TRUE) new("M",
**>>>
**>> callNextMethod()))
**>> [1] "["
**>>
**>>> a<-new("M",matrix(1:12,4,3))
**>>> a[1:2,2:3]
**>>>
**>> An object of class "M"
**>> [,1] [,2]
**>> [1,] 5 9
**>> [2,] 6 10
**>>
**>>>
**>>>
**>> Is there a problem with my method definition for the array-extending
**>> class?
**>>
**>> My work-around is as follows:
**>>
**>>> setMethod("[", "A", function(x, i, j, ..., drop = TRUE) new("A",
**>>>
**>> `[`(as(x,"array"), i=i, j=j, ..., drop=drop)))
**>> [1] "["
**>>
**>>> a[1:2,2:3,1]
**>>>
**>> An object of class "A"
**>> [,1] [,2]
**>> [1,] 5 9
**>> [2,] 6 10
**>>
**>>>
**>>>
**>> Cheers,
**>> Dan
**>>
**>> [[alternative HTML version deleted]]
**>>
**>> ______________________________________________
**>> R-devel_at_r-project.org mailing list
**>> https://stat.ethz.ch/mailman/listinfo/r-devel
**>>
**>>
*

[[alternative HTML version deleted]]

R-devel_at_r-project.org mailing list

https://stat.ethz.ch/mailman/listinfo/r-devel Received on Wed 21 Jul 2010 - 16:08:41 GMT

Archive maintained by Robert King, hosted by
the discipline of
statistics at the
University of Newcastle,
Australia.

Archive generated by hypermail 2.2.0, at Wed 21 Jul 2010 - 20:40:18 GMT.

*
Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-devel.
Please read the posting
guide before posting to the list.
*