[Rd] NAMESPACE choices for exporting S4 methods

Prof Brian Ripley ripley at stats.ox.ac.uk
Sat Dec 8 23:16:20 CET 2007

On Sat, 8 Dec 2007, Jay Emerson wrote:

> We are building a package, and want to create S4 methods for both head and
> mean for our own BigMatrix class.  Following the recommendation in "Writing
> R Extensions" we use exportMethods instead of export in NAMESPACE (this is
> described as being "clearer").  This works for head, but not for mean.
> Obviously we importFrom(utils, head), but don't need  to do this for mean,
> which is imported automatically from base.

And what is the error message?

> If we export(mean) rather than exportMethods(mean), it works as intended.
> A similar problem arises for a new generic function and an associated
> method, colmean, where the use of exportMethods(colmean) fails, but
> export(colmean) succeeds.
> We can build and use the package by using export instead of exportMethods,
> but we suspect that we're missing something that might be important to
> understand.
> Any hints or links to something we missed would be appreciated.

I know there are problems if you define a generic and no methods in a 
package (that is what stats4 does for AIC), but it doesn't sound as if 
that is what you are doing.  (Since the introduction of implicit generics 
- which may well apply to your mean() - it is possible to define a generic 
in a package without any methods stored there, not even a default method.)

I saw nothing in your description that is different from several other 
pacakges.  Without either the error messages or an example, we are reduced 
to guessing.  Can you make a minimal version available to us to look at?

Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

More information about the R-devel mailing list