Let's say I create custom function:
foo <- function(bar) {
c(x=bar, y=bar) }
I then create a custom "wrapper" function that contains this function and some other function:
foo2 <- function(...) {
dat <- foo(...)
plot(x = dat[1], y = dat[2], ...)
}
I've used ...
assuming both functions would have multiple arguments in a real world application.
- However, note that two different inner functions have an
...
.
Although this appears to work, it's not without warnings:
> foo2(bar=1)
Warning messages:
1: In plot.window(...) : "bar" is not a graphical parameter
2: In plot.xy(xy, type, ...) : "bar" is not a graphical parameter
3: In axis(side = side, at = at, labels = labels, ...) :
"bar" is not a graphical parameter
4: In axis(side = side, at = at, labels = labels, ...) :
"bar" is not a graphical parameter
5: In box(...) : "bar" is not a graphical parameter
6: In title(...) : "bar" is not a graphical parameter
Although R seems to be smart enough to apply unassigned arguments (i.e., those accounted for using the ...
) in my wrapper function to the appropriate inner function, it also appears as though the wrapper function still tries to apply the unassigned arguments to both inner functions.
- This results in a warning if one of the unassigned arguments (in this case
bar
) does not exist as a named argument for one of the inner functions (in this caseplot()
).
My question(s):
- Is there a way to avoid having these warnings appear?
- Is this even the appropriate way to approach this issue?