What does passing an ellipsis (...) as an argument mean in R?
r
Solution
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.
Problem
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, ...) ```