[Rd] Possible problem with namespaceImportFrom() and methods for generic primitive functions

John Chambers jmc at r-project.org
Fri Oct 18 23:20:25 CEST 2013

Very good report.

Should be fixed in the development version for 3.1.0 and in 3.0.2 patched. (svn revision 64076).


On Oct 18, 2013, at 8:51 AM, Karl Forner <karl.forner at gmail.com> wrote:

> Hi all,
> I have a problem with a package that imports two other packages which both
> export a method for the `[` primitive function.
> I set up a reproducible example here:
> https://github.com/kforner/namespaceImportFrom_problem.git
> Basically, the testPrimitiveImport package imports testPrimitiveExport1 and
> testPrimitiveExport2, which both export a S4 class and a `[` method for the
> class.
> Then:
> R CMD INSTALL -l lib testPrimitiveExport1
> R CMD INSTALL -l lib testPrimitiveExport2
> The command:
> R CMD INSTALL -l lib testPrimitiveImport
> gives me:
> Error in namespaceImportFrom(self, asNamespace(ns)) :
>  trying to get slot "package" from an object of a basic class ("function")
> with no slots
> I get the same message if I check the package (with R CMD check), or even
> if I try to load it using devtools::load_all()
> I tried to investigate the problem, and I found that the error arises in
> the base::namespaceImportFrom() function, and more precisely in
> this block:
>    for (n in impnames) if (exists(n, envir = impenv, inherits = FALSE)) {
>        if (.isMethodsDispatchOn() && methods:::isGeneric(n,  ns)) {
>            genNs <- get(n, envir = ns)@package
> Here n is '[', and the get(n, envir = ns) expression returns
> .Primitive("["), which is a function and has no @package slot.
> This will only occur if exists(n, envir = impenv, inherits = FALSE) returns
> TRUE, i.e. if the '[' symbol is already in the imports env of the package.
> In my case, the first call to namespaceImportFrom() is for the first import
> of testPrimitiveExport1, which runs fine and populate the imports env with
> '['.
> But for the second call, exists(n, envir = impenv, inherits = FALSE) will
> be TRUE, so that the offending line will be called.
> I do not know if the problem is on my side, e.g. from a misconfiguration of
> the NAMESPACE file, or if it is a bug and in which case what should be done.
> Any feedback appreciated.
> Karl Forner
> 	[[alternative HTML version deleted]]
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel

More information about the R-devel mailing list