[Rd] depends/suggests when making a new generic to override a function in a user package

Dr Gregory Jefferis jefferis at mrc-lmb.cam.ac.uk
Fri Jul 6 12:57:44 CEST 2012


Dear R developers,

I would like to add a new S3 generic to override a function in a user package, specifically:

	STAR::as.repeatedTrain

I have followed the recommendation here:

	http://cran.r-project.org/doc/manuals/R-exts.html#Adding-new-generics

doing this:

as.repeatedTrain<-function(x,...){
 UseMethod("as.repeatedTrain")
}

as.repeatedTrain.default<-function(x,...) {
 STAR::as.repeatedTrain(x)
}

but the question now arises, how do I make sure that my as.repeatedTrain generic function is used in preference to STAR's. If my package suggests STAR, then STAR will likely be loaded afterwards and my generic will get clobbered. So at the moment I have made my package depend on STAR rather than suggest it. However I will only occasionally use STAR, and it is quite a big package with a number of dependencies and I would prefer to avoid this. Is there another approach? I assume this isn't a problem for a non-generic in a base package because they are loaded first.

Many thanks for any suggestions,

Greg Jefferis.
--
Gregory Jefferis, PhD                      
Division of Neurobiology                   
MRC Laboratory of Molecular Biology,       
Hills Road,                                
Cambridge, CB2 0QH, UK.                    

http://www2.mrc-lmb.cam.ac.uk/group-leaders/h-to-m/g-jefferis
http://www.neuroscience.cam.ac.uk/directory/profile.php?gsxej2
http://flybrain.stanford.edu



More information about the R-devel mailing list