[Rd] environment question
pdalgd at gmail.com
Sun May 18 01:00:21 CEST 2014
On 17 May 2014, at 19:42 , Mick Jordan <mick.jordan at oracle.com> wrote:
> According to
> "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: R_GlobalEnv>
> <environment: namespace:base>
> This makes sense, however I have two questions on things that don't seem
> to make sense:
> <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!)
> In eval.R in library/base/R:
> .GlobalEnv <- environment()
> parent.frame <- function(n = 1) .Internal(parent.frame(n))
> 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.
> Mick Jordan
> [[alternative HTML version deleted]]
> R-devel at r-project.org mailing list
Peter Dalgaard, Professor,
Center for Statistics, Copenhagen Business School
Solbjerg Plads 3, 2000 Frederiksberg, Denmark
Email: pd.mes at cbs.dk Priv: PDalgd at gmail.com
More information about the R-devel