What do ..1 and ..2 stand for in R? [duplicate]
Asked Answered
A

1

6

Quote from R language definition:

Notice that identifiers starting with a period are not by default listed by the ls function and that ‘...’ and ‘..1’, ‘..2’, etc. are special.

The following identifiers have a special meaning and cannot be used for object names if else repeat while function for in next break TRUE FALSE NULL Inf NaN NA NA_integer_ NA_real_ NA_complex_ NA_character_ ... ..1 ..2 etc.

However it does not give any further detail. Could anyone elaborate?

Armchair answered 25/10, 2014 at 13:22 Comment(0)
F
8

These are used to positionally extract values from the ... argument of a function. See example below:

myfun <- function(...) {
   list(a = ..1, b = ..2, c = ..3)
}

myfun(1,2,3)
# $a
# [1] 1
# $b
# [1] 2
# $c
# [1] 3

myfun(3,2,1)
# $a
# [1] 3
# $b
# [1] 2
# $c
# [1] 1

myfun(1:5, "hello", letters[1:3])
# $a
# [1] 1 2 3 4 5
# $b
# [1] "hello"
# $c
# [1] "a" "b" "c"

This use becomes obvious if you try to call one of these from the console:

> ..1
Error: ..1 used in an incorrect context, no ... to look in
Follmer answered 25/10, 2014 at 13:28 Comment(2)
Good answer. Can't see where this would be useful. +1Saltant
There is an example in methods:::rbind .Bert

© 2022 - 2024 — McMap. All rights reserved.