[R] How get list element name in R 3.2.0

Marc Girondot marc_grt at yahoo.fr
Sun Apr 26 22:28:49 CEST 2015


Dear list-members,
I find a annoying difference between R 3.1.3 and R 3.2.

To get the element name of a list within lapply() or mclapply() call, I 
used the trick below:
For example:

essai <- list(T2345=c(5, 6, 7), T5664=c(9, 12, 17, 16))
lapply(essai, function(x) plot(x, main= names(essai)[substitute(x)[[3]]]))

It works fins in R 3.1.3 however in R 3.2 it produces an error:
 > essai <- list(T2345=c(5, 6, 7), T5664=c(9, 12, 17, 16))
 > lapply(essai, function(x) plot(x, main= 
names(essai)[substitute(x)[[3]]]))

  Error in names(essai)[substitute(x)[[3]]] :
   type 'symbol' d'indice incorrect

I don't see if this difference is noted is the list of changes:
http://cran.r-project.org/doc/manuals/r-devel/NEWS.html

If it is not a bug but a feature, what is the new way to get the list 
element name within a lapply or mclappy function.

Thanks a lot

Marc Girondot



More information about the R-help mailing list