Skip to contents

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_(...)

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.

Value

The return value of the call.

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))

Note

When the environment of the call head differs from that of the arguments, do may make a temporary binding of ... to pass arguments. This will cause some primitive functions, like ( <-, or for), to fail with an error like "'...' used an in incorrect context," because these primitives do not understand how to unpack .... To avoid the use of ..., ensure that all args have the same environment as the call head, or are forced.

For the specific case of calling <-, you can use set_ to make assignments.

See also

get_call do.call match.call set_