0

... is fine to dispatch additional arguments to functions within a function. I use it, among others, to maintain parsimonious function declarations with not a ton of arguments. But sometimes, I would need that more than a single function could make use of additional arguments passed to the function.

Maybe an example would make this clear:

heart <- structure(c(200, 162, 116, 99, 118, 164, 202, 242, 288, 305, 
                     284, 238, 37, 76, 108, 154, 200, 211, 175, 211, 197, 151, 105, 
                     73), .Dim = c(12L, 2L), .Dimnames = list(NULL, c("x", "y")))

# both functions in this function would benefit using `...`
plot_this <- function(xy, ...){
  plot(xy, ...)
  polygon(xy, ...)
}

Then, calling this function with arguments that only "concern" one function (ie asp for plot and density for polygon) will (most of the time) work but with warnings.

plot_this(heart, asp=1, density=30)

Warning messages:
1: In plot.window(...) : "density" is not a graphical parameter
2: In plot.xy(xy, type, ...) : "density" is not a graphical parameter
3: In axis(side = side, at = at, labels = labels, ...) :
  "density" is not a graphical parameter
4: In axis(side = side, at = at, labels = labels, ...) :
  "density" is not a graphical parameter
5: In box(...) : "density" is not a graphical parameter
6: In title(...) : "density" is not a graphical parameter

I understand that these warnings are perfectly legitimate and useful.

Is there a mechanism to deal with dispatching ellipsis to the 'right' functions when more use ... within a function?".

I'm looking for something:

  • more elegant than using this pattern ..._polygon or args.polygon
  • possibly simpler than around formals as answered there
  • less rough than suppressWarnings()
Community
  • 1
  • 1
Vincent Bonhomme
  • 7,235
  • 2
  • 27
  • 38
  • 2
    See a similar post [here](http://stackoverflow.com/questions/16774946/passing-along-ellipsis-arguments-to-two-different-functions) and its linked posts – alexis_laz Mar 28 '16 at 09:01
  • Thnaks! Precisely I would like to avoid `args.polygon` here, possibly know if there is a simpler way than [this one](http://stackoverflow.com/a/4128401/6101188). – Vincent Bonhomme Mar 28 '16 at 09:04
  • edited my post thanks to your comment. – Vincent Bonhomme Mar 28 '16 at 09:10
  • 3
    What's wrong with using `formals`? I'm tempted to close this as unclear as you haven't provided any reasoning for not using the builtin functionality in order to achieve what you need. It mainly sounds to me like "*but I don't wanna!*" – David Arenburg Mar 28 '16 at 09:14
  • I thought there could be a simpler way that I'm not aware of but I can manage with formals if there is not. – Vincent Bonhomme Mar 28 '16 at 09:18
  • `base` plotting functions contain many examples -that I guess could be considered simple/elegant (?)- of either (1) `..., polygon.args = list(arg1 = , ..), plot.args = list(arg1 = ), ...`followed by a `do.call` or `..., arg1.polygon = , arg1.plot = , ...` passed directly to each sub-funtion. See, e.g., `boxplot.default`, `barplot.default`, `legend` etc – alexis_laz Mar 28 '16 at 10:00

0 Answers0