Skip to contents

Decompose an R function

Usage

ast_decompose(x)

Arguments

x

a function

Value

result of utils::getParseData(), a data.frame; but we wrap it in a thin S3 wrapper to make it easy to see how the function changes as you modify it with ast_modify()

Examples

foo <- function(x) {
  x + 1
}
foo(5)
#> [1] 6
df <- ast_decompose(foo)
#> Error in as_string(x): Can't convert a logical vector to a string.
df
#> function (x, df1, df2, ncp, log = FALSE) 
#> {
#>     if (missing(ncp)) 
#>         .Call(C_df, x, df1, df2, log)
#>     else .Call(C_dnf, x, df1, df2, ncp, log)
#> }
#> <bytecode: 0x564bf3967008>
#> <environment: namespace:stats>
data.frame(df)
#> Error in as.data.frame.default(x[[i]], optional = TRUE): cannot coerce class ‘"function"’ to a data.frame
attributes(df)
#> NULL
attr(df, "expr")
#> NULL
attr(df, "expr")[1,"text"] # the original fxn
#> NULL