I have been having difficulty finding information about how to pass a list to a function in R.
I have used this approach before, e.g.
plot(list(x=1,y=1))
but the following example gives me an error:
foo <- function(a, b) c <- a + b
foo(list(a=1,b=1))
Error in foo(list(a = 1, b = 1)) :
argument "b" is missing, with no default
Furthermore, ?function doesn’t work and help('function') does not provide information on passing a list to a function.
update
To clarify, I understand how I can use a list as a single argument, but I was confused because I was under the impression that a property of functions was that multiple arguments could be passed as a list. It appears that this impression was incorrect. Rather, many functions are written specifically to handle lists, as described in the comments and answers below.
Use do.call
Alternatively you can do