On Fri, 2 Sep 2005, Spencer Graves wrote:

>         Permit a mild protest on the word "appropriate" in this context.  The
> global assignment operator "<<-" provides, for my tastes, excessive
> opportunities for problems.  If I define "x" someplace else and then
> call your function, it may change my "x" in ways that generate
> considerable wailing and gnashing of teeth.

No, no, no.

The sensible and appropriate uses of <<- involve modifying a variable that 
already exists in the lexical parent environment.  In these cases it can't 
escape and ravage the calling environment.

Certainly using <<- to assign to the calling environment is bogus.  In 
addition to your complaints, it doesn't even work (except from the global 
environment), since <<- searches the lexical stack rather than the call 
stack.

In R, <<- can be used safely to maintain state inside a function or shared 
between a set of functions (as in demo(scoping), or demo(tkdensity)). In 
S-PLUS it is admittedly harder to come up with good uses.

        -thomas

______________________________________________
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html

Reply via email to