(PR#1715) Re: package `methods' has persistent effects even if detached

Kurt Hornik Kurt.Hornik@wu-wien.ac.at
Fri, 28 Jun 2002 12:19:23 +0200


>>>>> Martin Maechler writes:

>>>>> "KH" == Kurt Hornik <hornik@ci.tuwien.ac.at> writes:
>>>>> Prof Brian D Ripley writes:
>>> Sorry, forgot to say this is in R-devel (2002-06-27) but not in 1.5.1.
>>>> class
>>> .Primitive("class")
>>>> find("class")
>>> [1] "package:base"
>>>> library(methods)
>>>> class
>>> .Primitive("dataClass")
>>>> find("class")
>>> [1] "package:methods" "package:base"
>>>> get("class", "package:base")
>>> .Primitive("dataClass")
>>>> detach("package:methods")
>>>> class
>>> .Primitive("dataClass")

>>> so attaching methods is altering the class object *in base*.
>>> Related to namespaces?

KH> A problem in library(), maybe?

KH> All I see is

KH> R/class.R:class <- dataClass

KH> but surely assignments should be in methods and not in base?

> I think JMC mentioned something about the reasons for this, 
> and will again (?) when `morning has broken' at the East cost
> (and Luke can chime in a bit later ... when the sun touches Midwest.. :-)

> My guess is: This is *necessary* now that base is a namespaced,
>    since everything in base is using class() as defined in base!
>    {use it's own name space first!}.

Again, not my understanding of Luke's paper.

The culprit is

    for(i in rev(seq(along = search())))
      cacheMetaData(as.environment(i), TRUE)
    if (! identical(environment(log), .GlobalEnv)) { # check if namespace used
        # if base is using a name space then any replacements for functions
        # in base defined in methods need to be installed directly into base
        # or they will not be visible to base code.
        for (n in ls(env = where))
            if (exists(n, env = NULL))
                assign(n, get(n, env = where), env = NULL)
    }

in .First.lib() of methods.

There is a general issue here: base should conceptually be considered as
sealed.  If we really need to unlock the bindings when attaching methods
then we should restore the original ones when detaching but it does not
feel right to do this at all.  Luke will have more to say, I am sure.

-k

> Martin

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-devel-request@stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._