[Rd] Possible problem with S4 dispatch

Seth Falcon sfalcon at fhcrc.org
Tue May 1 06:48:56 CEST 2007


First a bit of disclaimer...  I haven't isolated this problem into an
easy to reproduce case, and I won't be surprised if the root cause is
a fault in my code's use of name spaces or some such.

The error I'm seeing is one in which the desired method is not found.
What worries me in terms of my expectations of how to debug the
problem is that showMethods and selectMethod both find the method.
Here is an example browser session:

    ## Input 1, a character vector
    Browse[1]> gN[1:3]
    [1] "1005_at"   "1007_s_at" "1008_f_at"
    ## Input 2, an object of class AtomicAnnMap (subclass of AnnMap)
    Browse[1]> class(LLe)
    [1] "AtomicAnnMap"
    [1] "AnnotationDbi"
    ## See what selectMethod has to say (it finds the method I'm expecting)
    Browse[1]> selectMethod("mget", signature(x="character", envir=class(LLe)))
    Method Definition:
    function (x, envir, mode = "any", ifnotfound = list(function(x) stop(paste("value for '", 
        x, "' not found", sep = ""), call. = FALSE)), inherits = FALSE) 
        .checkNamesExist(x, names(envir))
        as.list(envir, names = x)
    <environment: namespace:AnnotationDbi>
            x           envir         
    target  "character" "AtomicAnnMap"
    defined "ANY"       "AnnMap"      
    ## Call it (we get base::mget, not the generic and hence an error)
    Browse[1]> mget(gN[1:3], LLe)
    Error in mget(x, envir, mode, ifnotfound, inherits) : 
    	second argument must be an environment
    Browse[1]> find("mget")
    [1] "package:AnnotationDbi" "package:base"         

The package code I'm working with imports the package that defines the
mget method (and this package does exportMethods(mget)), yet the
problem seems to be that the mget generic is not found -- but I find
it confusing that selectMethod works here.

+ seth

Seth Falcon | Computational Biology | Fred Hutchinson Cancer Research Center

More information about the R-devel mailing list