1

Say I write the following function

f = function(x, y, ...){
    plot(x, ...)
    lines(y, col='red', ...)
}

This throws an error when I call f with the argument col=. I know how to find what arguments are passed with ..., but I would like to remove col from them if it is there, so the following works. How can I do that ?

m0nhawk
  • 22,980
  • 9
  • 45
  • 73
statquant
  • 13,672
  • 21
  • 91
  • 162

1 Answers1

3

If you want to set that value it would be easiest to just intercept that one as well to prevent it from going into the ... in the first place.

f = function(x,y,col='red',...){
 plot(x,...)
 lines(y,col=col,...)
}

Or you can do grab the dots and adjust them, but then you have to pass along arguments as we list via do.call

f = function(x,y,...){
 plot(x,...)
 dots <-list(...)
 dots$col<-NULL
 do.call(lines, c(list(y,col="red"), dots))
}
MrFlick
  • 195,160
  • 17
  • 277
  • 295