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.
do.call(what, args)
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.# creating the functionmyfunction <- function(a,b) { a + b }# creating the list of arguments to the function callmyargs <- list(c(7, 9, 2), c(6, 2, 8))# implementing the do.call() functiondo.call(myfunction, myargs)