> -----Original Message-----
> It may be helpful not to worry about the technical details, 
> just to look at the source code defining the function:  if it 
> is defined in a place where a variable can be seen, it can 
> see that variable.

I too find R's lexical scoping rules straightforward.
However, I'd say that if your code relies on lexical scoping to find something, 
you should probably rewrite your code.

The number of times I've seen new R users get unexpected results because they 
haven't noticed that their function is referencing a parent environment instead 
of a locally defined variable or argument is past counting.

Of course there are times when it's useful and sensible to have globally 
defined variables that can be accessed within a function. But they are very 
rare; as a default, I'd recommend avoiding it if at all possible. If your 
function needs something from outside, pass it as an argument.



*******************************************************************
This email and any attachments are confidential. Any use...{{dropped:8}}

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to