Create a list of functions from a vector of characters

后端 未结 3 1449
醉酒成梦
醉酒成梦 2021-01-12 08:12

Thanks in advance, and sorry if this question has been answered previously - I have looked pretty extensively. I have a dataset containing a row of with concatenated informa

3条回答
  •  礼貌的吻别
    2021-01-12 08:47

    Maybe initialize your list with a single generic function, and then update them using:

    foo <- function(x){x+3}
    > body(foo) <- quote(x+4)
    > foo
    function (x) 
    x + 4
    

    More specifically, starting from a character, you'd probably do something like:

    body(foo) <- parse(text = "x+5")
    

提交回复
热议问题