Skip to content

Possible bug in base::namespaceImportFrom?

2 messages · Seth Falcon, Martin Maechler

#
Hi,

namespaceImportFrom in base/R/namespace.R has the following:

       fdef <- methods:::getGeneric(genName, impenv)

The definition of getGeneric is in methods/R/RMethodUtils.R starts
with:

    getGeneric <-
      ## return the definition of the function named f as a generic.
      ##
      ## If there is no definition, throws an error or returns
      ## NULL according to the value of mustFind.
      function(f, mustFind = FALSE, where = .genEnv(f, topenv(parent.frame()), package),
               package = "")

I think the call to getGeneric in namespaceImportFrom should use named
arguments because impenv, an environment, will be assigned to the
mustFind arg which is most likely not desired.

An example where this seems to show up is in the check reports for
GOstats:

   http://bioconductor.org/checkResults/1.9/gopher5-GOstats-checksrc.html

Here's the snip from the check output (the results may have been
updated in the meantime):

    * checking whether the name space can be loaded with stated dependencies ... WARNING
    Loading required package: methods
    Error in if (mustFind) stop(gettextf("no generic function found for \"%s\"",  : 
    	argument is not interpretable as logical
    In addition: Warning message:
    the condition has length > 1 and only the first element will be used in: if (mustFind) stop(gettextf("no generic function found for \"%s\"",  
    Execution halted

I'm having trouble reproducing it on my local system, but thought I
would bring it to the team's attention.

Best,

+ seth
#
Seth> Hi, namespaceImportFrom in base/R/namespace.R has the
    Seth> following:

    Seth>        fdef <- methods:::getGeneric(genName, impenv)

    Seth> The definition of getGeneric is in
    Seth> methods/R/RMethodUtils.R starts with:

    Seth>     getGeneric <- 
    ......
    Seth>  function(f, mustFind = FALSE, where = .........)

    Seth> I think the call to getGeneric in namespaceImportFrom
    Seth> should use named arguments because impenv, an
    Seth> environment, will be assigned to the mustFind arg
    Seth> which is most likely not desired.

Indeed. Well spotted, Seth!
Fixed and committed for R-devel and R-beta.

Martin