5

I recently thought about the ... argument for a function and noticed that R does not allow to check the class of the object.

f <- function(...) {
   class(...)
}

f(1, 2, 3)
## Error in class(...) : 3 arguments passed to 'class' which requires 1

Now with the quote

“To understand computations in R, two slogans are helpful:

• Everything that exists is an object. • Everything that happens is a function call."

— John Chambers

in my head I'm wondering: What kind of object is ...?

s1624210
  • 627
  • 4
  • 11
  • 3
    [Section 1.5.2 of the R Internals manual](https://cran.r-project.org/doc/manuals/r-release/R-ints.html#Dot_002ddot_002ddot-arguments) may be somewhat helpful. They are a special type of "pairlist". [Section 1.1.1](https://cran.r-project.org/doc/manuals/r-release/R-ints.html#SEXPTYPEs) tells us "Pairlists are rarely seen at R level, but are for example used for argument lists." Other things that are pairlists are language objects, such as formulas. – duckmayr Jun 13 '20 at 21:06

1 Answers1

4

What an interesting question!

Dot-dot-dot ... is an object (John Chambers is right!) and it's a type of pairlist. Well, I searched the documentation, so I'd like to share it with you:

R Language Definition document says:

The ‘...’ object type is stored as a type of pairlist. The components of ‘...’ can be accessed in the usual pairlist manner from C code, but is not easily accessed as an object in interpreted code. The object can be captured as a list.

Another chapter defines pairlists in detail:

Pairlist objects are similar to Lisp’s dotted-pair lists.

Pairlists are handled in the R language in exactly the same way as generic vectors (“lists”).

Help on Generic and Dotted Pairs says:

Almost all lists in R internally are Generic Vectors, whereas traditional dotted pair lists (as in LISP) remain available but rarely seen by users (except as formals of functions).

And a nice summary is here at Stack Overflow!