Creating functions example
rlang::new_function()
creates a function from its three components and supports tidy evaluationAlternative to function factories.
Example:
power <- function(exponent) {
new_function(
exprs(x = ),
expr({
x ^ !!exponent
}),
caller_env()
)
}
power(0.5)
#> function (x)
#> {
#> x^0.5
#> }
Another example, is graphics::curve
that allows you to plot an expression without creating a function. It could be implemented like this: