fun: A compact way to define a function.

Description Usage Arguments Details Value Note Author(s) Examples

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

1
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.

Details

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

Value

A newly constructed function.

Note

Since it doesn't know which symbols you intend to be arguments and which you intend to take from the enclosing environment, it captures all symbols in defaults; therefore it won't work as a closure that reflects changes in the enclosing environment.

Author(s)

Peter Meilstrup

Examples

1
2
3
4
5
6
7
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
# }

crowding/vadr documentation built on May 14, 2019, 11:33 a.m.