[Rd] is.environment, as.environment, and NULL
Peter Dalgaard BSA
28 Aug 2001 10:38:49 +0200
Prof Brian Ripley <firstname.lastname@example.org> writes:
> > A question, and a remark.
> > Question, would we want to keep as.environment(NULL) to give the base
> > package, so that code like ls(envir = NULL) will still work?
> Interesting. Was it ever documented to?
Implicitly at least, but ls("package:base") has been preferable for a
> > Remark, we once discussed making package environments (in particular for
> > base) read-only. One way of doing this is via setting attributes, but
> > we cannot do this on NULL. Not that I think this is the way to do it,
> > though ...
> NULL is just shorthand: there is a proper R object for base:
> > .GlobalEnv
> <environment: R_GlobalEnv>
> > is.null(.GlobalEnv)
>  FALSE
> It was news to me that NULL for .GlobalEnv worked at R level.
It doesn't. NULL is the *base* environment i.e. the one at the very
end of the search path. This is what gives the mess where things like
evalq(foo(x), NULL) will find "foo" in base, but not in a package.
(One gotcha being that taking environment(formula) returns NULL if no
environment was ever set.)
O__ ---- Peter Dalgaard Blegdamsvej 3
c/ /'_ --- Dept. of Biostatistics 2200 Cph. N
(*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918
~~~~~~~~~~ - (email@example.com) 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: firstname.lastname@example.org