Learn R Programming

nseval (version 0.5.1)

do: Making function calls, with full control of argument scope.

Description

The functions do and do_ construct and invoke a function call. In combination with dots and quotation objects they allow you to control the scope of the function call and each of its arguments independently.

Usage

do(...)

do_(...)

Value

The return value of the call.

Arguments

...

A function to call and list(s) of arguments to pass. All should be quotation or dots objects, except the first argument for do which is quoted literally.

Details

For do_ all arguments should be quotation or dots objects, or convertible to such using as.quo(). They will be concatenated together by c.dots to form the call list (a dots object). For do the first argument is quoted literally, but the rest of the arguments are evaluated the same way as do_.

The head, or first element of the call list, represents the function, and it should evaluate to a function object. The rest of the call list is used as that function's arguments.

When a quotation is used as the first element, the call is evaluated from the environment given in that quotation. This means that calls to caller() (or parent.frame()) from within that function should return that environment.

do is intended to be a replacement for base function do.call. For instance these two lines are similar in effect:

do.call("complex", list(imaginary = 1:3))
do(complex, dots(imaginary = 1:3))

As are all these:

do.call("f", list(as.name("A")), envir = env)
do_(quo(f, env), quo(A, env)):
do_(dots_(list(as.name("f"), as.name("A")), env))
do_(dots_(alist(f, A), env))

See Also

get_call do.call match.call set_