as_function() transforms a one-sided formula into a function.
This powers the lambda syntax in packages like purrr.
as_function( x, env = global_env(), ..., arg = caller_arg(x), call = caller_env() ) is_lambda(x)
A function or formula.
If a function, it is used as is.
If a formula, e.g.
If a string, the function is looked up in
Environment in which to fetch the function in case
These dots are for future extensions and must be empty.
An argument name as a string. This argument will be mentioned in error messages as the input that is at the origin of a problem.
The execution environment of a currently
running function, e.g.
f <- as_function(~ .x + 1) f(10)#>  11g <- as_function(~ -1 * .) g(4)#>  -4h <- as_function(~ .x - .y) h(6, 3)#>  3# Functions created from a formula have a special class: is_lambda(f)#>  TRUEis_lambda(as_function(function() "foo"))#>  FALSE