Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Passing list of named parameters to function?

Tags:

r

Almost there: try

do.call(runif,c(list(n=100),params)) 

Your variant, list(n=100,params) makes a list where the second element is your list of parameters. Use str() to compare the structure of list(n=100,params) and c(list(n=100),params) ...


c(...) has a concatenating effect, or in FP parlance, a flattening effect, so you can shorten the call; your code would be:

params <- list(min=0, max=1)
do.call(runif, c(n=100, params))

Try the following comparison:

params = list(min=0, max=1)
str(c(n=100, min=0, max=1))
str(list(n=100, min=0, max=1))
str(c(list(n=100),params))
str(c(n=100,params))

Looks like if a list is in there at any point, the result is a list ( which is a desirable feature in this use case)