What is the do.call() function in R?

Overview

The do.call() function in R constructs and executes a function call from a name or a function as well as a list of arguments to be passed to it. In other words, the do.call() function allows us to call the R function using a list to hold the function’s arguments instead of writing out the arguments.

Syntax

do.call(what, args)
Syntax for the do.call() function

Parameter value

The do.call() function takes the following parameter values:

  • what: This represents either the function or a non-empty character and names the function to be called.
  • args: This represents the list of arguments to the function call.

Example

# creating the function
myfunction <- function(a,b) { a + b }
# creating the list of arguments to the function call
myargs <- list(c(7, 9, 2), c(6, 2, 8))
# implementing the do.call() function
do.call(myfunction, myargs)

Free Resources