user1172468
user1172468

Reputation: 5464

What is the proper way to use a list for vector in r for the multiple parameter portion of a function call?

Let us saw we have a function defined as:

foobar(string.argument, ...) 

let us say we have a list

my.list <- list("a", "b", "c", "d")

how can we invoke foobar equivalent to:

foobar("some value", "a", "b", "c", "d") 

of course using my.list for the variable parameter list.

Upvotes: 0

Views: 24

Answers (1)

LyzandeR
LyzandeR

Reputation: 37879

do.call would probably help you do what you want:

my.list <- list("a", "b", "c", "d")
#add 'some value' to my.list
my.list <- c('some value', my.list)

do.call(foobar, my.list)

do.call will run foobar having as arguments the elements in my.list.

Upvotes: 2

Related Questions