...
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
orargs.polygon
- possibly simpler than around
formals
as answered there - less rough than
suppressWarnings()