[R] The assign(paste(...,i),...) idiom

baptiste auguie ba208 at exeter.ac.uk
Tue Apr 21 00:06:40 CEST 2009


I vaguely recall thinking with such convoluted constructs when  
switching from Matlab to R. The lack of generic data structures such  
as lists makes you define variable names that you can identify and  
manipulate. There are structures in Matlab, but I think they are much  
less used than lists in R.

I was wondering earlier how to help newcomers understand the  
limitations of this strange and unnecessary construct without going  
through the details of each particular example that comes up in the r- 
help list. Perhaps a simple generic and illustrative example in the R  
wiki? (say, (i) list some data files in a directory, (ii)load into  
data.frames, (iii)manipulate some columns, (iv)store in a list,  
(v)manipulate the list, (vi)plot some results).

Now, how would we go about naming that entry...? Perhaps 'A beginner's  
assignment'


baptiste


On 20 Apr 2009, at 22:44, Stavros Macrakis wrote:

> Judging from the traffic on this mailing list, a lot of R beginners
> are trying to write things like
>
>      assign( paste( "myvar", i), ...)
>
> where they really should probably be writing
>
>      myvar[i] <- ...
>
> Do we have any idea where this bizarre habit comes from?
>
>          -s
>
> ______________________________________________
> R-help at 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.

_____________________________

Baptiste Auguié

School of Physics
University of Exeter
Stocker Road,
Exeter, Devon,
EX4 4QL, UK

Phone: +44 1392 264187

http://newton.ex.ac.uk/research/emag




More information about the R-help mailing list