[R] How to define S4 methods for '['

From: Berton Gunter <gunter.berton_at_gene.com>
Date: Tue 21 Jun 2005 - 06:24:43 EST


This is a question about the S4 formal class system.

Suppose I have a class, 'foo', defined by:

setClass('foo',representation(dat='matrix', id='character') )

I wish to define a '[' method for foo that will extract from the 'dat' slot. I would have thought that the following would work, but it doesn't:

setMethod("[","foo",function(x,i, j, .,drop=TRUE)callGeneric(x@dat,i, j,drop=drop) )

The only way I have succeeded in defining this method is using brute force eval(parse(. :


This works. However, I am not able under any circumstances to pass the drop argument -- it is ignored.

I would appreciate any pointers about how to do this properly. If this is explicitly in the Green Book (I do not have it with me at the moment), that will suffice.


Bert Gunter

        [[alternative HTML version deleted]]

R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Tue Jun 21 06:28:16 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:32:54 EST