Martin Morgan
2012-Feb-26 06:39 UTC
[Rd] improved error message when existing implicit S4 generic is not imported?
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 -- Computational Biology Fred Hutchinson Cancer Research Center 1100 Fairview Ave. N. PO Box 19024 Seattle, WA 98109 Location: M1-B861 Telephone: 206 667-2793
Prof Brian Ripley
2012-Feb-27 08:22 UTC
[Rd] improved error message when existing implicit S4 generic is not imported?
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
Apparently Analagous Threads
- S4 NAMESPACE method imports and exports do not include (promoted?) generics
- R CMD check fails to warn about undocumented classes and methods
- .onLoad failing because could not find function "loadMethod"
- S4 Generics and NAMESPACE : justified warning ?
- namespace S3 and S4 generic imports cannot both be satisfied: