vadr (version 0.01)

fun: A compact way to define a function.

Description

fun captures its first argument unevaluated and turns it into a function. Every name used in the expression becomes an argument, unless it looks like a function call. If you don't intend to capture a particular variable, you can not provide it, and it will use a default value that pulls from the enclosing scope.

Usage

fun(expr, .all.names=FALSE)

Arguments

expr
The expression to use as the function's body.
.all.names
Whether to include call heads as parameters.

Value

A newly constructed function.

Details

"..." is supported in the function definitions and should behave as you expect.

Examples

Run this code
f <- fun(x/y)
f(10,2)  # prints 5
f
# function (x = eval(quote(x),..fun_envir),
#           y = eval(quote(y),..fun_envir) {
#   x/y
# }

Run the code above in your browser using DataLab