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

后端 未结 2 1173
误落风尘
误落风尘 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:22

    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
    

提交回复
热议问题