Skip to content
Prev 48292 / 63424 Next

environment question

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