[Rd] .onLoad failing because could not find function "loadMethod"

Hervé Pagès hpages at fhcrc.org
Sat Oct 15 02:46:07 CEST 2011


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



More information about the R-devel mailing list