The following code does work but I cannot find any documentation about the "..
" (dot dot) operator in the data.table
help and vignette:
library(data.table)
cols <- c("mpg", "gear")
DT <- as.data.table(mtcars)
DT[ , ..cols]
The output is:
mpg gear
1: 21.0 4
2: 21.0 4
3: 22.8 4
4: 21.4 3
5: 18.7 3
...
Why does this work, is there any documentation for that?
PS: Normally I would use mget
etc...
Edit 1: This is not a plain R feature of the reserved names ...
, ..1
, ..2
etc., which are used to refer to arguments passed down from a calling function (see ?Reserved
). My example uses not a number, but characters after the two dots.
Edit 2: This is no duplicate, as the example of Rich Scriven shows:
> mtcars[, ..cols]
Error in `[.data.frame`(mtcars, , ..cols) : object '..cols' not found
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…