environment question
On 17 May 2014, at 19:42 , Mick Jordan <mick.jordan at oracle.com> wrote:
According to :https://stat.ethz.ch/R-manual/R-devel/library/base/html/environment.html "If |fun| is a function or a formula then |environment(fun)| returns the environment associated with that function or formula. If |fun| is |NULL| then the current evaluation environment is returned."
environment()
<environment: R_GlobalEnv>
environment(environment)
<environment: namespace:base> This makes sense, however I have two questions on things that don't seem to make sense: 1.
.Internal(environment(NULL))
<environment: base> Since we are calling from R_GlobalEnv, how can the calling environment be base?
Read the Description section in ?.Internal carefully.... Basically, you are calling .Internal from the command line. It is not designed to be called from there and only wizards know what happens if it is. (The set of wizards who might know whether it makes any sense at all does not include me!)
2. In eval.R in library/base/R: .GlobalEnv <- environment() parent.frame <- function(n = 1) .Internal(parent.frame(n)) etc. Since the functions being defined are in base, how can the calling environment be R_GlobalEnv. Or does this just set .GlobalEnv temporarily to base?
.GlobalEnv is a variable in base alright. The assignment happens when base is being loaded and _at that point_ the environment is R_GlobalEnv.
Thanks Mick Jordan [[alternative HTML version deleted]]
______________________________________________ R-devel at r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Peter Dalgaard, Professor, Center for Statistics, Copenhagen Business School Solbjerg Plads 3, 2000 Frederiksberg, Denmark Phone: (+45)38153501 Email: pd.mes at cbs.dk Priv: PDalgd at gmail.com