0

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 case plot()).

My question(s):

  1. Is there a way to avoid having these warnings appear?
  2. Is this even the appropriate way to approach this issue?
theforestecologist
  • 4,667
  • 5
  • 54
  • 91
  • 1
    https://stackoverflow.com/questions/16774946/passing-along-ellipsis-arguments-to-two-different-functions or https://stackoverflow.com/questions/5080972/using-multiple-ellipses-arguments-in-r or https://stackoverflow.com/questions/42007678/using-multiple-three-dot-ellipsis-in-r might be helpful – thelatemail Jul 19 '17 at 03:39
  • @thelatemail Thanks! I looked forever for useful posts, but didn't find any of these. After rummaging through those links and posts linked to them, I think the most useful similar post is here: [Is there a way to use two '…' statements in a function in R?](https://stackoverflow.com/q/4124900/4581200) – theforestecologist Jul 19 '17 at 03:48
  • However, that post is from 7 years ago. I wonder if there is a more straightforward / elegant approach to this now?? – theforestecologist Jul 19 '17 at 03:50

0 Answers0