What do ..1 and ..2 in R?

Quote from the definition of the language R:

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

The following identifiers have special meaning and cannot be used for object names if else is repeated while the function in the next break is TRUE FALSE NULL Inf NaN NA NA_integer_ NA_real_ NA_complex_ NA_character _..... 1..2, etc.

However, he does not provide any further details. Can anyone clarify?

+6
source share
1 answer

They are used to positionally extract values ​​from an argument ... function. See the 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 usage becomes apparent if you try to call one of them from the console:

 > ..1 Error: ..1 used in an incorrect context, no ... to look in 
+8
source

Source: https://habr.com/ru/post/977214/


All Articles