Is it possible to have multiple ellipsis arguments in an R function? A simplified version of what I’m trying to do is this:
plotgenerator<-function(x,y,...,...,...){
plot(x,y,...)
axes(...)
legend(...)
}
My thought was to use optional string arguments, like this:
plotgenerator<-function(x,y,plotargs="",axesargs="",legendargs=""){
plot(x,y,plotargs)
axes(axesargs)
legend(legendargs)
}
But that doesn’t work. Does anyone know if something like this is possible? I have searched a lot for this, but a search string like “R …” isn’t actually very helpful 😉
You could so something similar to your second choice if you use
do.call, which allows you to pass the arguments to a function as a list. E.g. passaxesargas a list and then in your function have:do.call(axes,axesarg)etcFor example:
In the above, any arguments that should be handled by the
inner_fxn...should be passed in with in theinner_argslist. Theouter_fxn...arguments are handled as usual.