Hervé Pagès
2011-Oct-15 00:46 UTC
[Rd] .onLoad failing because could not find function "loadMethod"
Hi, This strange warning happen sometimes when running 'R CMD check': * checking whether the package can be loaded with stated dependencies ... WARNING Error : .onLoad failed in loadNamespace() for ?pkgB?, details: call: length(new("A")) error: could not find function "loadMethod" Error: package/namespace load failed for ?pkgB? Execution halted It looks like this package (or one of its dependent packages) has an unstated dependence on a standard package. All dependencies must be declared in DESCRIPTION. See the information on DESCRIPTION files in the chapter ?Creating R packages? of the ?Writing R Extensions? manual. The same warning is reported during the 2 next checks: * checking whether the package can be unloaded cleanly ... WARNING <same error here> * checking whether the namespace can be loaded with stated dependencies ... WARNING <same error here> It seems to happen when pkgB has code in its .onLoad hook that tries to call a method defined in pkgA (pkgB imports pkgA) on an object 'x' that is an instance of a class defined in pkgA. For some obscure reason it seems that, at the time the .onLoad hook is executed, the methods package (which is imported in both packages) is not working properly. I've put 2 toy packages here that illustrate the problem: https://rapidshare.com/files/4043144391/pkgA_1.0.tar.gz https://rapidshare.com/files/1959508331/pkgB_1.0.tar.gz I'm using R version 2.14.0 alpha (2011-10-10 r57211). The .onLoad hook in pkgB is: .onLoad <- function(libname, pkgname) { showMethods("length") length(new("A")) } Class A and the length method for this class is defined in pkgA. Because of the showMethods("length") statement, you should see this when running R CMD check pkgB_1.0.tar.gz: * checking whether the package can be loaded with stated dependencies ... WARNING Function: length (package base) x="A" Error : .onLoad failed in loadNamespace() for ?pkgB?, details: call: length(new("A")) error: could not find function "loadMethod" Error: package/namespace load failed for ?pkgB? Execution halted Any insight on this would be appreciated. Thanks, H. -- Herv? Pag?s Program in Computational Biology Division of Public Health Sciences Fred Hutchinson Cancer Research Center 1100 Fairview Ave. N, M1-B514 P.O. Box 19024 Seattle, WA 98109-1024 E-mail: hpages at fhcrc.org Phone: (206) 667-5791 Fax: (206) 667-1319
Hervé Pagès
2011-Oct-15 00:47 UTC
[Rd] .onLoad failing because could not find function "loadMethod"
On 11-10-14 05:46 PM, Herv? Pag?s wrote: [...]> > I've put 2 toy packages here that illustrate the problem: > > https://rapidshare.com/files/4043144391/pkgA_1.0.tar.gz > > https://rapidshare.com/files/1959508331/pkgB_1.0.tar.gzarghh, sorry for the broken links. I'll try to put those packages somewhere else. H.
Uwe Ligges
2011-Oct-15 15:41 UTC
[Rd] .onLoad failing because could not find function "loadMethod"
The thing that happens during the check is that the methods package is not among the automatically loaded and attached packages. When the pkgB packages is attached, the Namespaces of pkgA and methods are loaded but not attached. Note that one of the checks tells you: "A namespace must be able to be loaded with just the base namespace loaded: otherwise if the namespace gets loaded by a saved object, the session will be unable to start." If you like to see into the details more easily, just start R with R R_DEFAULT_PACKAGES=NULL and then try to library("pkgB") and you are able to reproduce the check messages. You can avoid n-1 Warnings/Errors in the checks by adding library("methods") in your .onLoad function, but of course you cannot get rid of the check that checks that the package can be loaded with the base namespace only. Best, Uwe Ligges On 15.10.2011 02:46, Herv? Pag?s wrote:> Hi, > > This strange warning happen sometimes when running 'R CMD check': > > * checking whether the package can be loaded with stated dependencies > ... WARNING > > Error : .onLoad failed in loadNamespace() for ?pkgB?, details: > call: length(new("A")) > error: could not find function "loadMethod" > Error: package/namespace load failed for ?pkgB? > Execution halted > > It looks like this package (or one of its dependent packages) has an > unstated dependence on a standard package. All dependencies must be > declared in DESCRIPTION. > See the information on DESCRIPTION files in the chapter ?Creating R > packages? of the ?Writing R Extensions? manual. > > The same warning is reported during the 2 next checks: > > * checking whether the package can be unloaded cleanly ... WARNING > <same error here> > * checking whether the namespace can be loaded with stated dependencies > ... WARNING > <same error here> > > It seems to happen when pkgB has code in its .onLoad hook that > tries to call a method defined in pkgA (pkgB imports pkgA) on an object > 'x' that is an instance of a class defined in pkgA. For some obscure > reason it seems that, at the time the .onLoad hook is executed, the > methods package (which is imported in both packages) is not working > properly. > > I've put 2 toy packages here that illustrate the problem: > > https://rapidshare.com/files/4043144391/pkgA_1.0.tar.gz > > https://rapidshare.com/files/1959508331/pkgB_1.0.tar.gz > > I'm using R version 2.14.0 alpha (2011-10-10 r57211). > > The .onLoad hook in pkgB is: > > .onLoad <- function(libname, pkgname) > { > showMethods("length") > length(new("A")) > } > > Class A and the length method for this class is defined in pkgA. > > Because of the showMethods("length") statement, you should see this > when running R CMD check pkgB_1.0.tar.gz: > > * checking whether the package can be loaded with stated dependencies > ... WARNING > Function: length (package base) > x="A" > > Error : .onLoad failed in loadNamespace() for ?pkgB?, details: > call: length(new("A")) > error: could not find function "loadMethod" > Error: package/namespace load failed for ?pkgB? > Execution halted > > Any insight on this would be appreciated. > > Thanks, > H. >
Possibly Parallel Threads
- improved error message when existing implicit S4 generic is not imported?
- Are downstream dependencies rebuilt when a package is updated on CRAN?
- "False" warning on "replacing previous import" when re-exporting identical object
- S4 Generics and NAMESPACE : justified warning ?
- S4 NAMESPACE method imports and exports do not include (promoted?) generics