[Rd] combining generics/methods from multiple packages

Randall Pruim rpruim at calvin.edu
Tue Jul 29 05:56:56 CEST 2014


I’m wondering if there is any way for me to create a generic function in a package that merges the generics and methods from two or more packages that each define a generic with the same name, but have non intersecting instances.

Here is an example.  dplyr and MASS both define an S3 generic select() but define no colliding methods.  Just to make life extra interesting, there is also utils::select.list() which is not intended to be a method for select() and in fact wants to receive a character vector, not a list.

I would like to create a generic select() in my package such that

1) select.ridgelm <- MASS:::select.ridgelm  [Note: this is not exported.]

2) select.data.frame <- dplyr::select.data.frame [Also not exported.] etc. for other methods in this package.

3) utils::select.list does NOT act like the select method for lists.

The only way I have been able to figure out how to do this requires use of the ::: operator, so let me add criterion 4:

4) The resulting package must pass CRAN checks without issues.

Is this possible?  If so how?

My goal is to have select() work on objects that either package can handle without having to use MASS::select() or dplyr::select().

Thanks in advance for any help — even if it is an explanation for why this is impossible and I should stop trying.

—rjp



More information about the R-devel mailing list