[ESS] r-related question: editing NAMESPACEd functions in packages

Martin Maechler maechler at stat.math.ethz.ch
Sun Nov 20 22:33:27 CET 2011


>>>>> Vitalie Spinu <spinuvit at gmail.com>
>>>>>     on Sun, 20 Nov 2011 14:44:39 +0100 writes:

    >> 
    >> Probably I am missing  something but how exactly
    >> attach(asNamespace(.)) solves the problem? The functions
    >> in the attached namespace cannot see the objects in
    >> .GlobalEnv the same way how functions in namespaces
    >> attached by library cannot see those.

    > To make the attach(asNamespace(.))  work, one would have
    > to change the environment of all functions in attached
    > namespace to .GlobalEnv and attach the package imports, to
    > make sure .GlobalEnv has precedence and imports are
    > visible as well. Messy stuff :(

Indeed.  Michael made a very good point about the recursive imports(),
and even w/o that, my "trick" hasn't been clean

    > Methods apparently behave differently. If you redefine a
    > method from attached namespace in .GlobalEnv, functions
    > from namespace will use the method from .GlobalEnv and not
    > the one in the namespace. Looks like
    > attach(asNamespace(.)) is a way to go for S4 development
    > at least.

"a way" yes, and as I've been working quite a bit with S4
methods, it has often helped me...

But as said above, it's not clean, there should be something better.

(but that should/will depend on how  R 2.15.0 (and later) will
 look; as said, that should be a topic on the R-devel mailing
 list ...  but I must devote my time to something else for a while)
 
Martin



More information about the ESS-help mailing list