Re: [Rd] improved error message when existing implicit S4 generic is not imported?

From: Prof Brian Ripley <ripley_at_stats.ox.ac.uk>
Date: Mon, 27 Feb 2012 08:22:09 +0000

I think the message is accurate [*]: you do however need to have a clear understanding of the scoping issues involved, and no message is going to give you that.

In short, implicit generics are converted (or not) into explicit functions to be dumped during the dump-for-lazy-loading phase of R CMD INSTALL: loading the namespace finds whatever function of that name is in scope at that time, and once there are multiple functions of the same name around, different ones may be in scope at different times.

To take one recent example from CRAN:

> library(VGAM) # fine, as VGAM loads stats4 via Depends:

and in another session

> loadNamespace('VGAM')

Error: Functions for exporting methods must have been made generic, explicitly or implicitly; not true when loading ‘VGAM’ for ‘AIC’, ‘logLik’

since the visible function AIC() when the namespace alone is loaded is the one in stats, not the one in stats4 which was visible when the package was dumped for lazy-loading.

I have little idea how one could express all the possibilities for user error in an error message like this: as the CRAN maintainers have found, some package authors cannot comprehend even several-paragraph explanations tailored to their specific errors. But I might have written something like:

The function 'plot' found when exporting methods from the namespace 'pkgB' is not an S4 generic.

Hopefully such experiences will encourage people to write NAMESPACE files more carefully, and also to import generics from e.g. stats4 which was long ago provided for that purpose. (Re another message: stats4 *is* "methodsGenerics" for base packages.)

[*] at least now that it tells you which namespace is involved, unlike the original version ....

On 26/02/2012 06:39, Martin Morgan wrote:
> pkgA's NAMESPACE has
>
> importFrom(graphics, plot)
> exportClasses("A")
> exportMethods("plot")
>
> R/foo.R has
>
> setClass("A")
> setMethod("plot", "A", function(x, y, ...) {})
>
> During R CMD INSTALL pkgA_1.0.tar.gz we are told
>
> ** preparing package for lazy loading
> Creating a generic function for 'plot' from package 'graphics' in
> package 'pkgA'
> ** help
> No man pages found in package ‘pkgA’
> *** installing help indices
> ** building package indices
> ** testing if installed package can be loaded
>
> * DONE (pkgA)
>
> pkgB has in its DESCRIPTION
>
> Depends; pkgA
>
> with NAMESPACE
>
> importFrom(graphics, plot)
> exportClasses("B")
> exportMethods("plot")
>
> R/bar.R has
>
> setClass("B")
> setMethod("plot", "B", function(x, y, ...) {})
>
> During R CMD INSTALL pkgB_1.0.tar.gz we are told
>
> ** preparing package for lazy loading
> ** help
>
> i.e., no implicit generic created (because graphics::plot already has an
> implicit generic created, when the pkgA dependency was attached?). and also
>
> ** testing if installed package can be loaded
> Error : Functions for exporting methods must have been made generic,
> explicitly or implicitly; not true when loading 'pkgB' for 'plot'
> Error: loading failed
> Execution halted
> ERROR: loading failed
>
> which doesn't seem accurate, rather "'pkgB' does not import S4 implicit
> generic for 'plot' created by 'pkgA'"
>
> > sessionInfo()
> R Under development (unstable) (2012-02-25 r58492)
> Platform: x86_64-unknown-linux-gnu (64-bit)
>
> Martin

-- 
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

______________________________________________
R-devel_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Received on Mon 27 Feb 2012 - 08:24:31 GMT

This quarter's messages: by month, or sorted: [ by date ] [ by thread ] [ by subject ] [ by author ]

All messages

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Thu 01 Mar 2012 - 20:40:23 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-devel. Please read the posting guide before posting to the list.

list of date sections of archive