Skip to content

environment question

5 messages · Peter Dalgaard, Mick Jordan, Simon Urbanek

#
On 17 May 2014, at 19:42 , Mick Jordan <mick.jordan at oracle.com> wrote:

            
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!)
.GlobalEnv is a variable in base alright. The assignment happens when base is being loaded and _at that point_ the environment is R_GlobalEnv.

  
    
#
On 5/17/14, 4:00 PM, peter dalgaard wrote:
Well, calling from the shell. Anyway, I was just surprised by the result 
as, notwithstanding the fact that .Internal is "special", the calling 
environment is definitely .globalEnv. The enclosing environment might 
well be different, but that's not what environment(NULL) returns. My 
curiosity relates to the fact that the two calls have different stack 
depths, so that the .Internal(environment(NULL)) call has to detect 
whether it was called via environment() or .Internal(environment(NULL)) 
in order to return the right answer.
Sorry, I don't understand how that can be. The function definitions in, 
say, eval.R, and all the others in library/base/R, end up in base, as 
made clear by ls(baseenv()). So if these files are evaluated in the 
"usual way", and the environment() call in eval.R returns globalenv(), 
then they would, in fact, be defined there and not in baseenv. Now, I 
realise that this is startup code, so perhaps the implementation does 
something special and these files really aren't evaluated in the "usual" 
way.

Mick
#
On May 17, 2014, at 7:26 PM, Mick Jordan <mick.jordan at oracle.com> wrote:

            
.Internal() doesn't setup a context for the evaluation environment so sysparent doesn't reflect the evaluation environment. That's why environment() only works when used as a closure, compare:
<environment: R_GlobalEnv>
<environment: base>
<environment: R_GlobalEnv>

Again, you have been warned not to call .Internal() unless you know what you're doing so you should know what is actually happening if you call it ;).
More importantly that's not the value forever - note that later there is

.GlobalEnv <- globalenv()

in base/R/Rprofile which is loaded *after* base/R/*.R which is the value you see when you check after base is locked.

Cheers,
Simon
#
On 5/17/14, 9:02 PM, Simon Urbanek wrote:
Thanks, those were exactly the kind of answers that I wanted.
That's what I thought might be happening - should have checked the site 
profile. Now I'm just curious why it's important to have a value for 
.GlobalEnv during the loading of the base .R files.

Mkick