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
if (FALSE) { # \dontrun{
# 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] }
# Call it
result <- fn(DiscountRate = c(R1=0.05, R2=0.07), r = "R1")
# Returns: 0.05
} # }
