From sfalcon at fhcrc.org  Tue May  1 18:52:24 2007
From: sfalcon at fhcrc.org (Seth Falcon)
Date: Tue, 01 May 2007 09:52:24 -0700
Subject: [Rd] Possible problem with S4 dispatch
References: <m27irtkv2f.fsf@ziti.local>
	<Pine.LNX.4.64.0705010907260.16158@gannet.stats.ox.ac.uk>
Message-ID: <m2bqh4jxkn.fsf@ziti.local>

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



[Rd] Possible problem with S4 dispatch
Seth Falcon