Getting the parse tree for a predefined function in R

前端 未结 3 1952
[愿得一人]
[愿得一人] 2021-02-10 05:30

I feel as if this is a fairly basic question, but I can\'t figure it out.

If I define a function in R, how do I later use the name of the function to get its parse tree.

3条回答
  •  被撕碎了的回忆
    2021-02-10 06:00

    Apparently that's indeed some weird quirk of substitute and is mentioned here:

    /* do_substitute has two arguments, an expression and an environment (optional). Symbols found in the expression are substituted with their values as found in the environment. There is no inheritance so only the supplied environment is searched. If no environment is specified the environment in which substitute was called is used. If the specified environment is R_GlobalEnv it is converted to R_NilValue, for historical reasons. In substitute(), R_NilValue signals that no substitution should be done, only extraction of promise expressions. Arguments to do_substitute should not be evaluated. */

    And you have already found a way of circumventing it:

    e = new.env()
    e$fn = f
    substitute(fn, e)
    

提交回复
热议问题