3

quoted from Hadley's book advanced R: Environments

The enclosing environment belongs to the function, and never changes, even if the function is moved to a different environment.

the following code shows the enclosing environment of f is modified to be environment e. So what does it mean exactly by saying 'enclosing environment does not change'?

f = function() { }   
environment(f) # <environment: R_GlobalEnv>
e = new.env()        
environment(f) = e   
environment(f) #  <environment: 0x2a01c88>
Mike Wise
  • 22,131
  • 8
  • 81
  • 104
Jim Green
  • 261
  • 4
  • 10
  • `e$f()` evalutes to 2 because `environment(e$f)` is still `globalenv()`. maybe I overread the quoted statement from Hadley? enclosing environment can definitely change if you modify it. – Jim Green Feb 18 '16 at 08:13
  • I edited the scroll bars away. I hate those things :). – Mike Wise Feb 18 '16 at 08:30

0 Answers0