← Back to R Course | Chapter 5: Functions | Lesson 7 of 7

Variadic Functions (...)

In this page:

  1. Variadic Functions (...)

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

markup
sum_all <- function(...) {
  values <- c(...)
  sum(values)
}

cat(sum_all(1, 2, 3), "\n")
cat(sum_all(10, 20, 30, 40), "\n")
🔒

Chapter Quiz — Complete all 7 topics to unlock

0/7 topics done

Complete these topics first:

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.