[Bioc-devel] BiocGenerics / NAMESPACE question

Kasper Daniel Hansen kasperdanielhansen at gmail.com
Mon Dec 5 22:29:18 CET 2011


2011/12/5 Hervé Pagès <hpages at fhcrc.org>:

> Right. I found this in the "Writing R Extensions" manual:
>
>  Note that exporting methods on a generic in the namespace will also
>  export the generic, and exporting a generic in the namespace will
>  also export its methods.
>
> I didn't know this. But it sounds more like a "convenience" feature
> to me and maybe it's "cleaner design" to not to rely on it?

I find it completely natural that exportMethod will also export the
generic since there cannot really be a method without a generic.  That
export also exports all methods is perhaps not completely obvious but
the only possible usecase would be if you want to hide some methods,
which I cannot really imagine.

R-devel exts says

"Where a generic has been created in the package solely to add S4
methods to it, it can be declared via either or both of exports or
exportMethods, but the latter seems clearer (and is used in the stats4
example above). On the other hand, where a generic is created in a
package without setting any methods for it (such as AIC in stats4),
exports must be used."

and also for imports

"Note that importMethodsFrom will also import any generics defined in
the namespace on those methods."

Based on this it seems like BiocGenerics is absolutely doing the right
thing by using export() for generics without methods, but that
packages in general should use exportMethods and importMethodsFrom in
order to export/import methods and their generics.  Guess that we need
to use importFrom to catch the generics from BiocGenerics.

Thanks for the help and for pointing out the discussion in R-exts.
Kasper



More information about the Bioc-devel mailing list