Some times there is a function which has an arbitrary number of arguments. For example, the bootstrapPage
function of package shiny. If I have a data.frame and I want to create one widget for one row, then I have not figured out a pretty way to pass the number of arguments according to the row number of the data.frame. So far, I generate the script and use the trick of eval(parse(text="..."))
In fact, the structure of arguments passed to function in R (key and value) is similar to a list
, so I am wondering if there is a way to pass the argument as a list in R.
More specifically, if I have a function f
and a list argv
, is there a way to pass the objects in argv
to f
according to the matching of the name of argv
and the name of the arguments of f
, and the position in argv
and the position in the arguments of f
?
For example, let
f <- function(a, b) a + b
argv <- list(a=1, b=2)
How should I pass the argv
to f
which is equivalent to f(a=argv$a, b=argv$b)
?
Or if we have:
f <- function(a, b, ...) { # some codes }
argv <- list(a = 1, b = 2, 3, 4, 5)
How should I pass the argv
to f
which is equivalent to f(a=argv$a, b=argv$b, argv[[3]], argv[[4]], argv[[5]])
?
Thanks!