Using a single object to pass multiple arguments to a function?

function, r

Solution

Are you looking for `do.call`?

> args=list(1,2,3)
> do.call(add.these,args)
[1] 6

Problem

Let's say I have a function that can't be altered, like: ``` add.these <- function(x,y,z) { x + y + z } ``` And I want to pass all three arguments as a single object. How do I pass this single object through to the function so it evaluates them as separate inputs? The ideal result would be something like `args <- list(x,y,z)`, and `add.these(args)` returns the result. It's a simple question that's been bothering me but I've stupidly been unable to figure it out. The actual use case is that the function has variable numbers of arguments it requires depending on the desired outputs, and I want to pass these through as a list or something.

Original source