Avoiding the infamous “eval(parse())” construct

后端 未结 2 1183
误落风尘
误落风尘 2020-12-01 09:29

Ok, so I\'m running some loops to process data stored in list objects. Ever mindful of the infamous fortune admonishment not to use eval(parse(mystring))

2条回答
  •  时光说笑
    2020-12-01 10:24

    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 <- bar
    
    mylist[[rab]][['oof']]
    #or
    mylist[[ c(rab,'oof') ]]
    

提交回复
热议问题