Coerce to function.
This generic transforms objects to functions. It is especially useful with formulas to create lambdas on the fly.
- A function or formula.
If a function, it is used as is.
If a formula, e.g.
~ .x + 2, it is converted to a function with two arguments,
.y. This allows you to create very compact anonymous functions with up to two inputs.
- Additional arguments passed on to methods. Currently unused in rlang.
f <- as_function(~ . + 1) f(10)