do.call
Execute a Function Call

Description

Executes a function call, given a function and the argument list.

Usage

do.call(what, args, quote = FALSE, envir = parent.frame())

Arguments

what the function to call. Can be specified as either a function object or a character string, which is then found in the environment specified by envir, and from which the function object is produced.
args a list of the arguments to the called function. The names attribute of args gives the argument names.
quote a logical flag. If FALSE (the default), each element of args is evaluated in envir when the function first reads the argument. If TRUE, each element of args is conceptually wrapped in a call to quote, so the value is not evaluated again when the function first reads the argument.
envir the environment used to evaluate the function. This environment is also used to look up the function if it is specified as a character string,and to evaluate the elements of args (if quote is FALSE).

Details

do.call provides a more efficient way to evaluate a function than constructing and evaluating an expression that calls the function.
The quote argument does nothing for arguments that evaluate to themselves, such as double vectors and other constant data values, and expression objects. However, if the list args contains symbols or call objects, then the quote argument determines whether these values are evaluated in the environment envir. This evaluation is done lazily: that is, only when the function being called reads these arguments. If the function never refers to these arguments, they are not evaluated.
Value
returns the result of the evaluated call.
See Also
quote.
Examples
x <- function(x,y) x+y
do.call("x",list(1,2))
do.call(x,list(1,2))
do.call(function(x,y)x+y,list(1,2))
# all above return 3

A <- 11 B <- 22 do.call(paste, list(as.name('A'), as.name('B')), quote=TRUE) # returns "A B" do.call(paste, list(as.name('A'), as.name('B')), quote=FALSE) # returns "11 22"

A <- 11 f <- function(x) x+100 # define global "f" and "A" (in global env) myenv <- new.env() assign("A", 22, envir=myenv) assign("f", function(x) x+200, envir=myenv) # define local "f" and "A" (in myenv)

do.call(f,list(A),envir=myenv) # returns 111 (use global "f", "A")

do.call("f",list(A),envir=myenv) # returns 211 (evaluate "f" in myenv)

do.call(f,list(quote(A)),envir=myenv) # returns 122 (evaluate "A" in myenv)

do.call("f",list(quote(A)),envir=myenv) # returns 222 (evaluate "f", "A" in myenv)

Package base version 6.0.0-69
Package Index