[R] use value in variable to be name of another variable

Rolf Turner r.turner at auckland.ac.nz
Tue Jul 12 00:31:20 CEST 2016


On 12/07/16 10:13, Matthew wrote:
> Hi Jim,
>
>    Wow ! And it does exactly what I was looking for.  Thank you very much.
>
> That assign function is pretty nice. I should become more familiar with it.

Indeed you should, and assign() is indeed nice and useful and handy. 
But it should be used with care and circumspection.  It *alters the 
global environment* which is fraught with peril.  Generally speaking 
most things that can be done with assign() (and its companion function 
get()) are better and more safely done using lists and functions and 
other "natural" R-ish constructs.  Resist the temptation to turn R into 
a macro language.

cheers,

Rolf Turner

-- 
Technical Editor ANZJS
Department of Statistics
University of Auckland
Phone: +64-9-373-7599 ext. 88276



More information about the R-help mailing list