as_function

0th

Percentile

Coerce to function.

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.
Aliases
  • as_function
Examples
f <- as_function(~ . + 1)
f(10)
Documentation reproduced from package rlang, version 0.0.0.9000, License: GPL-3

Community examples

Looks like there are no examples yet.