Recompose an R function
Examples
foo <- function(x) {
x + 1
}
foo(5)
#> [1] 6
# decompose the function
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>
# recompose the function
fun <- ast_recompose(df)
#> Error: x must be of class ast, data.frame
fun
#> Error: object 'fun' not found
parse(text = fun)
#> Error: object 'fun' not found
eval(parse(text = fun))
#> Error: object 'fun' not found
eval(parse(text = fun))(5)
#> Error: object 'fun' not found