From: John Chambers <jmc_at_r-project.org>

Date: Wed, 21 Jul 2010 08:58:14 -0700

R-devel_at_r-project.org mailing list

https://stat.ethz.ch/mailman/listinfo/r-devel Received on Wed 21 Jul 2010 - 15:59:55 GMT

Date: Wed, 21 Jul 2010 08:58:14 -0700

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.

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
**>
*

R-devel_at_r-project.org mailing list

https://stat.ethz.ch/mailman/listinfo/r-devel Received on Wed 21 Jul 2010 - 15:59:55 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 - 19:50: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.
*