[Rd] Behaviour of environment(foo)<- (PR#1509)
Jonathan Rougier
J.C.Rougier@durham.ac.uk
Fri, 03 May 2002 11:49:25 +0100
Peter Dalgaard BSA wrote:
>
> J.C.Rougier@durham.ac.uk writes:
>
> > Hi Everyone,
> >
> > I've noticed that setting the environment of a function from a package
> > actually creates a copy of that function in .GlobalEnv and sets the
> > environment on this copy:
> >
> > > find(.profile)
> > [1] "package:newblips"
> > > environment(.profile) <- bb1$getEnv() # this is an environment
> > > find(.profile)
> > [1] ".GlobalEnv" "package:newblips"
> >
> > I don't have a problem with this behaviour (now I understand it!) but
> > I think that it would help to document it in the help file. May I
> > suggest that instead of
> >
> > The assignment form sets the environment of the function or
> > formula `fun' to the `value' given.
> >
> > we have
> >
> > The assignment form sets the environment of the function or
> > formula \code{fun} to \code{value} if \code{fun} is in the
> > current environment, otherwise it makes a copy of \code{fun} in
> > the current environment and sets the environment of the copy.
> >
> > I think that describes the current procedure: please correct me if I
> > am wrong!
>
> But this is generic behaviour for *all* attribute assignment. It makes
> no sense to describe a specific instance of it. Consider
>
> data(airquality)
> f<-function() { x <- class(airquality)<-NULL; ls() }
> f()
> class(airquality)
I understand. However, I still think that the help page for environment
is wrong! Using "enviroment<-" does not necessarily set the environment
of the function, as stated. What happened to me is that I modified
.profile in the package newblips and then re-assigned its environment
but didn't see any change, because it was masked by the copy of .profile
in .GlobalEnv that I didn't know I had. That's quite a subtle outcome
and I think that changing the environment help page would clarify this
for other users. J.
--
Jonathan Rougier Science Laboratories
Department of Mathematical Sciences South Road
University of Durham Durham DH1 3LE
tel: +44 (0)191 374 2361, fax: +44 (0)191 374 7388
http://www.maths.dur.ac.uk/stats/people/jcr/jcr.html
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._