Converts an AST expression to an executable R function. The function arguments are automatically detected from symbols in the AST, or can be explicitly specified.
Usage
as_rfunction(x, args = NULL, envir = parent.frame(), ...)Examples
# Simple expression: DiscountRate[r]
ast <- ast_expression(
op = "[",
lhs = ast_symbol("DiscountRate"),
rhs = ast_symbol("r")
)
fn <- as_rfunction(ast)
# Creates: function(DiscountRate, r) { DiscountRate[r] }
fn(DiscountRate = c(R1 = 0.05, R2 = 0.07), r = "R1")
#> R1
#> 0.05
