The behavior of lambda
depends on the object that is passed to it.
The method for handling functions returns the function unchanged. The method
for handling symbols evaluates the symbol, then attempts to apply itself to the
result. For calls, lambda
creates a function that applies the new arguments,
along with the original arguments in the call, to the original call function.
lambda
attempts to parse a formula object - an object with syntax LHS ~ RHS
-
by using the value on the left-hand side as the function arguments and the value on
the right-hand side as the function body. The argument on the left-hand side
is split across "." so that multiple arguments can be easily created. For example,
lambda(x.y ~ sqrt(x + y))
creates function(x, y) sqrt(x + y)
.
If the formula is only one-sided, then the formula is parsed similar to the
method in the purrr
package; names that are prefixed by a "." are considered
the function arguments. The previous function could also be created using
lambda(~sqrt(.x + .y))
.
lambda
is used in many of the higher-order functions in the eList
package. It can also be used in other functions so that users have a variety
of options in which they satisfy functional arguments.