3

I have seen several related questions to the ellipses, but I am still not sure what it means to pass "..." as an argument. I am completely new to R, but am trying to understand what the following means:

forest <- randomForest(x = train.x, y = train.y, ...)
merlin2011
  • 71,677
  • 44
  • 195
  • 329
  • 1
    -1 because you either didn't read the manual or help pages (`?"..."` and `?dotsMethods`) or you didn't explain what was insufficient about them. – Joshua Ulrich Jul 17 '13 at 02:15
  • 3
    That's the weakest rationale I've heard in awhile. The manuals don't exist solely for those who are trying to "learn all of R". Use the search function of your PDF reader or browser for goodness sake! R's startup message tells you how to use the help functions. And "not easily available from a Google search"?!? I just searched "R ellipsis" and everything on the first page of results is relevant (even after removing this question from the set). This question is as useful as the duplicate I linked to. If you don't like that one [here's another](http://stackoverflow.com/q/5890576/271616). – Joshua Ulrich Jul 17 '13 at 20:50
  • -1 Asked **and** answered at least 3 times hereabouts, not counting the manuals. – Gavin Simpson Jul 17 '13 at 20:55

1 Answers1

16

The typical use of ... argument is when a function say f internally calls a function g and uses ... to pass arguments to g without explicitly listing all those arguments as its own formal arguments. One may want to do this, for example, when g has a lot of optional arguments that may or may not be needed by the user in the function f. Then instead of adding all those optional arguments to f and increasing complexity, one may simply use ....

What it means, as you asked, is the function f will simply ignore these and pass them on to g. The interesting thing is that ... may even have arguments that g does not want and it will ignore them too, for say h if it needed to use ... too. But also see this so post for a detailed discussion.

For example consider:

f <- function (x, y, ...) {
  # do something with x
  # do something with y
  g(...) # g will use what it needs
  h(...) # h will use that it needs
  # do more stuff and exit
}

Also, see here in the intro-R manual for an example using par.

Also, this post shows how to unpack the ... if one was writing a function that made use of it.

Community
  • 1
  • 1
asb
  • 4,392
  • 1
  • 20
  • 30