Avoiding the infamous "eval(parse())" construct Avoiding the infamous "eval(parse())" construct r r

Avoiding the infamous "eval(parse())" construct


Using get and [[:

bar <- list(foo = list(fast = 1:5, slow = 6:10),            oof = list(6:10, 1:5))rab <- 'bar'get(rab)[['oof']]# [[1]]# [1]  6  7  8  9 10# # [[2]]# [1] 1 2 3 4 5


If the name of your top list is going to change and be accessed by a variable with the name then it is best to put those lists into another list, then you can access the list you want using [[. Also read fortune(312) and the help on ?'[['.

You can then access the pieces in a different ways (detailed on the help page ?'[[').

mylist <- list()mylist$bar <- barmylist[[rab]][['oof']]#ormylist[[ c(rab,'oof') ]]