Skip to content
Prev 332666 / 398506 Next

Function does not see variables outside the function

On 05/11/2013 12:25, Rui Barradas wrote:
That is not correct.  The scoping rule when evaluatiing a function is to 
look first in the evaluation frame, then the function's environment (see 
?environment).  The parent frame is not part of the scope (unless part 
of the environment).

You can set a function's environment to emptyenv(): then there will be 
no search outside the function.  As that includes no search for any of 
the functions implementing R itself, only very simple functions will be 
self-contained.

You can control the search by setting a function's environment.  Most 
likely that will achieve what you want to do (but have not told us).