J.C.Rougier@durham.ac.uk
2002-May-03 10:12 UTC
[Rd] Behaviour of environment(foo)<- (PR#1509)
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! Cheers, Jonathan. --please do not edit the information below-- Version: platform = i686-pc-linux-gnu arch = i686 os = linux-gnu system = i686, linux-gnu status = major = 1 minor = 5.0 year = 2002 month = 04 day = 29 language = R Search Path: .GlobalEnv, package:newblips, package:MASS, package:mva, Autoloads, package:base -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
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) -- O__ ---- Peter Dalgaard Blegdamsvej 3 c/ /'_ --- Dept. of Biostatistics 2200 Cph. N (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~~~~~~~~~ - (p.dalgaard@biostat.ku.dk) FAX: (+45) 35327907 -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._