[Bioc-devel] a S4 dispatching question

Mike wjiang2 at fhcrc.org
Wed Aug 6 19:43:08 CEST 2014


I'd like to do 'data.table-like' subsetting on `S4 class` by using 'i 
expression'. However, '[' generic function has the problem to dispatch 
S4 method because of its early evaluation of i argument.
e.g.

 > gslist[Visit == 1, ]
Error in gslist[Visit == 1, ] :
   error in evaluating the argument 'i' in selecting a method for 
function '[': Error: object 'Visit' not found

Here 'gslist' is a S4 object `GatingSet` .

I wasn't able to bypass this even after I defined my own S3 method (e.g 
[.GatingSet).
I guess it is because 'GatingSet' is S4 class and there are already some 
S4 methods defined by other packages

 > showMethods("[")
Function: [ (package base)
x="AnnotatedDataFrame", i="ANY"
x="flowFrame", i="ANY"
...

So it will always try these S4 methods before any S3 gets its chance.

Is there better way other than these two?
1. change 'GatingSet' to S3 class
2. use a different generic function that is not associated with any S4 
methods (e.g. subset)

Mike



More information about the Bioc-devel mailing list