rlang (version 0.0.0.9000)

as_function: Coerce to function.

Description

This generic transforms objects to functions. It is especially useful with formulas to create lambdas on the fly.

Usage

as_function(.f, ...)

Arguments

.f
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, .x or . and .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.

Examples

Run this code
f <- as_function(~ . + 1)
f(10)

Run the code above in your browser using DataCamp Workspace