[R] Superassignment (<<-) and indexing

Spencer Graves spencer.graves at pdf.com
Sat Sep 3 00:28:49 CEST 2005

	  Wow!  That's great.  Thanks.  spencer

Thomas Lumley wrote:

> 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

Spencer Graves, PhD
Senior Development Engineer
PDF Solutions, Inc.
333 West San Carlos Street Suite 700
San Jose, CA 95110, USA

spencer.graves at pdf.com
www.pdf.com <http://www.pdf.com>
Tel:  408-938-4420
Fax: 408-280-7915

More information about the R-help mailing list