How do I substitute symbols in a language object?

后端 未结 3 981
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-11 07:05

Suppose I have the following language object:

lang <- quote( f(x=a) )

and I want to substitute in 1 for a. How

3条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-11 07:45

    Use do.call:

    do.call(substitute, list(lang, list(a=1)))
    

    By using do.call, we force evaluation of the name `lang` to its actual underlying value, f(x=a). Then substitution is performed on f(x=a), rather than the name `lang`.

提交回复
热议问题