Re: [Rd] Possible problem with S4 dispatch

From: Seth Falcon <sfalcon_at_fhcrc.org>
Date: Tue, 01 May 2007 09:52:24 -0700

Prof Brian Ripley <ripley_at_stats.ox.ac.uk> writes:
> Note that you called
>
> selectMethod("mget", signature(x="character", envir=class(LLe)))
>
> by name rather than calling the visible function mget() (which you
> could have supplied as fdef). I've never really got to the bottom of
> the complicated searches that getGeneric() uses, but the fact that it
> does not just look for a visible function of that name tells you it is
> doing something different.
>
> What I would check from your browser is what parent.env() shows,
> successively until you get to the imports and then the base
> namespace. If mget is not in the imports, something would seem to be
> up with your importing of namespaces. find() is not relevant here as
> namespace scoping is in play: only if the mget generic is imported
> will it take precedence over base:::mget. (It is not clear to me what
> is being browsed here, and hence what namespaces are in play.)

This was helpful. It seems that the strange behavior I was seeing was due to stale package installations. After reinstalling the package and all of its depends and imports, things are looking more normal.

I used the following function to examine the chain of parent environments while debugging:

    showEncEnvs <- function() {

        etmp <- parent.env(parent.frame())
        while (TRUE) {
            ename <- environmentName(etmp)
            cat(sprintf("Found envirnment: '%s'\n", ename))
            if (exists("mget", etmp, inherits=FALSE))
              cat("found mget\n")
            switch(ename,
                   "R_EmptyEnv"=break,
                   "R_GlobalEnv"=break)
            if (ename == "") {
                cat("**** first five entires\n")
                print(ls(etmp)[1:5])
            }
            etmp <- parent.env(etmp)
        }

    }

One thing to note: One might expect each import to be in the chain of parent environments. Instead all imports are merged into a single environment that is the parent of the package env.

+ seth

-- 
Seth Falcon | Computational Biology | Fred Hutchinson Cancer Research Center
http://bioconductor.org

______________________________________________
R-devel_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Received on Tue 01 May 2007 - 19:43:18 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Tue 01 May 2007 - 21:33:58 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-devel. Please read the posting guide before posting to the list.