ast_recompose: Recompose an R function

View source: R/ast_recompose.R

ast_recomposeR Documentation

Recompose an R function

Description

Recompose an R function

Usage

ast_recompose(x, as_expr = FALSE)

Arguments

x

an object of class ast

as_expr

(logical) return the function as an expression? default: FALSE

Value

a function as a character string, or an expression if as_expr=TRUE

Examples

foo <- function(x) {
  x + 1
}
foo(5)

# decompose the function
df <- ast_decompose(foo)
df

# recompose the function
fun <- ast_recompose(df)
fun

parse(text = fun)
eval(parse(text = fun))
eval(parse(text = fun))(5)

sckott/astr documentation built on Nov. 12, 2024, 4:19 p.m.