dots {base}R Documentation

..., ..1, etc used in Functions

Description

... and ..1, ..2 etc are used to refer to arguments passed down from a calling function. These (and the following) can only be used inside a function which has ... among it formal arguments.

...elt(n) is a functional way to get ..<n> and basically the same as eval(paste0("..", n)), just more elegant and efficient. Note that switch(n, ...) is very close, differing by returning NULL invisibly instead of an error when n is zero or too large.

...length() returns the number of expressions in .... This is the same as length(list(...)) but without evaluating the expressions in ... (which happens with list(...)).

Usage

...length()
...elt(n)

Arguments

n

a positive integer, not larger than the number of expressions in ..., which is the same as ...length() which is the same as length(list(...)), but the latter evaluates all expressions in ....

See Also

... and ..1, ..2 are reserved words in R, see Reserved.

For more, see the Introduction to R manual for usage of these syntactic elements, and dotsMethods for their use in formal (S4) methods.

Examples

tst <- function(n, ...) ...elt(n)
tst(1, pi=pi*0:1, 2:4) ## [1] 0.000000 3.141593
tst(2, pi=pi*0:1, 2:4) ## [1] 2 3 4
try(tst(1)) # -> Error about '...' not containing an element.

tst.dl <- function(x, ...) ...length()
tst.dl(1:10)    # 0  (because the first argument is 'x')
tst.dl(4, 5)    # 1
tst.dl(4, 5, 6) # 2  namely '5, 6'
tst.dl(4, 5, 6, 7, sin(1:10), "foo"/"bar") # 5.  Note: no evaluation!

[Package base version 3.5.0 Index]