Variadic Functions (...)
In this page:
Variadic Functions (...)
The special ... parameter lets a function accept any number of additional arguments, which can be forwarded to another function or collected into a list with list(...). Many built-in functions, like cat() and paste(), rely on ... to accept a flexible number of inputs. This is R's mechanism for variable-length argument lists.
Note: Use list(...) inside a function body to inspect or iterate over whatever extra arguments were passed in.
Example: Variadic Functions (...)
sum_all <- function(...) {
values <- c(...)
sum(values)
}
cat(sum_all(1, 2, 3), "\n")
cat(sum_all(10, 20, 30, 40), "\n")
Login to try C/C++/Java/PHP code in the editor
🔒
Chapter Quiz — Complete all 7 topics to unlock
0/7 topics done
Complete these topics first: