[Bioc-devel] avoiding clashes of different S4 methods with the same generic

Aaron Lun alun at wehi.edu.au
Tue Apr 26 20:00:49 CEST 2016

Dear List,

When a S4 method for the same class is defined in two separate packages 
(i.e., under the same generic), and both packages are loaded into a R 
session, it seems that the method from the package loaded later clobbers 
the method from the package loaded first. Is it possible to specifically 
call the method in the first package when both packages are loaded? If 
not, how should we protect against this?

To give some context; the csaw package currently defines a normalize() 
method for SummarizedExperiment objects, using the generic from 
BiocGenerics. However, if some other hypothetical package (I'll call it 
"swings", for argument's sake) were to define a normalize() method with 
a SE signature, and if the swings package were to be loaded after csaw, 
then it seems that all calls to normalize() would use the method defined 
by swings, rather than that defined by csaw.

Now, for usual functions, disambiguation would be easy with "::", but I 
don't know whether this can be done in the S4 system, given that the 
details of dispatch are generally hidden away. The only solution I can 
see is for csaw (and/or swings) to define a SE subclass; define the 
normalize() method using the subclass as the signature, such that S4 
dispatch will now go to the correct method; and hope that no other 
package redefines normalize() for the subclass.

Is this what I should be doing routinely, i.e., define subclasses and 
methods for those subclasses in all my packages? Or am I missing 
something obvious? I would have expected such clashes to be more of a 
problem, given how many new packages are being added to BioC at every 



More information about the Bioc-devel mailing list