When a function is called, R goes through a process of matching the arguments the caller used to formal arguments for the function. The match.call
function in R duplicates this process. So for example,
f <- function(x = 1, y, ...) {
match.call(expand.dots = FALSE)
}
f(2)
#> f(x = 2)
f(y = 3)
#> f(y = 3)
f(z = 4)
#> f(... = pairlist(z = 4))
Created on 2021-04-23 by the reprex package (v1.0.0)
You can see that z
, which is not a formal argument, gets caught up in the ...
argument, which is internally a "pairlist". You can use the ...
argument in
other calls; if f()
had
g(...)
in its body, then f(z = 4)
would end up calling g(z = 4)
, because the pairlist of arguments would be substituted for the ...
in the call. This is commonly used in the form list(...)
to turn ...
into a regular vector list: it calls the list()
function with arguments from the pairlist.
There are a few special constructions for working with ...
: see the ?"..."
help page for details.