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>