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.
Arguments
- ...
A function to call and list(s) of arguments to pass. All should be
quotation
ordots
objects, except the first argument fordo
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:
As are all these:
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.