[Rd] is.environment, as.environment, and NULL

Peter Dalgaard BSA p.dalgaard@biostat.ku.dk
28 Aug 2001 10:38:49 +0200


Prof Brian Ripley <ripley@stats.ox.ac.uk> 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
long time.

> > 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)
> [1] FALSE

Nope...

> It was news to me that NULL for .GlobalEnv worked at R level.
> 
> Brian

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
~~~~~~~~~~ - (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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._