When I look at the contents of [[.data.frame
on my PC, this is what I get:
当我看到[[.data.frame在我的电脑上的内容时,这就是我得到的:
> get("[[.data.frame")
function (x, ..., exact = TRUE)
{
na <- nargs() - (!missing(exact))
if (!all(names(sys.call()) %in% c("", "exact")))
warning("named arguments other than 'exact' are discouraged")
if (na < 3L)
(function(x, i, exact) if (is.matrix(i))
as.matrix(x)[[i]]
else .subset2(x, i, exact = exact))(x, ..., exact = exact)
else {
col <- .subset2(x, ..2, exact = exact)
i <- if (is.character(..1))
pmatch(..1, row.names(x), duplicates.ok = TRUE)
else ..1
.subset2(col, i, exact = exact)
}
}
<environment: namespace:base>
I've gotten used to ...
, but this is the first time I saw ..1
and ..2
. A quick search both in R help and Google returned mostly rubbish, since the dots are often interpreted as placeholders, so I'm hoping someone here can give me a pointer? Or am I missing something dreadfully obvious? Where do these come from and how can I use them?
我已经习惯了...,但这是我第一次看到..1和..2。快速搜索R帮助和谷歌返回主要是垃圾,因为点通常被解释为占位符,所以我希望有人在这里可以给我一个指针?还是我错过了一些非常明显的东西?这些来自何处以及如何使用它们?
2 个解决方案
#1
16
This is a way to reference the 1st, 2nd, ... elements of the special pairlist that is ...
. So ..1
is the way to refer to the first element of ...
, ..2
refers to the second element of ...
and so on.
这是引用特殊pairlist的第1,第2 ......元素的一种方式....所以..1是引用......的第一个元素的方式。,。2指的是第二个元素...的元素等等。
This is mentioned in the R Internals manual in section 1.5.2 Dot-dot-dot arguments, the relevant bit of which is:
这在R.2 Internals手册的1.5.2点 - 点点参数中提到,其相关位是:
The value of
...
is a (special) pairlist whose elements are referred to by the special symbols..1
,..2
, ... which have theDDVAL
bit set: when one of these is encountered it is looked up (viaddfindVar
) in the value of the...
symbol in the evaluation frame.......的值是一个(特殊的)pairlist,其元素由特殊符号引用..1,..2,...具有DDVAL位设置:当遇到其中一个时,它被查找(通过ddfindVar)在评估框架中的...符号的值。
#2
5
To add to Gavin's answer:
添加到Gavin的答案:
They are also mentioned briefly in the help page for reserved words (?Reserved
).
它们也在保留字的帮助页面中简要提及(?保留)。
A really simple example of usage is
一个非常简单的使用示例是
f <- function(...) print(..1)
f(x = 99) #prints 99
f() #throws an error
#1
16
This is a way to reference the 1st, 2nd, ... elements of the special pairlist that is ...
. So ..1
is the way to refer to the first element of ...
, ..2
refers to the second element of ...
and so on.
这是引用特殊pairlist的第1,第2 ......元素的一种方式....所以..1是引用......的第一个元素的方式。,。2指的是第二个元素...的元素等等。
This is mentioned in the R Internals manual in section 1.5.2 Dot-dot-dot arguments, the relevant bit of which is:
这在R.2 Internals手册的1.5.2点 - 点点参数中提到,其相关位是:
The value of
...
is a (special) pairlist whose elements are referred to by the special symbols..1
,..2
, ... which have theDDVAL
bit set: when one of these is encountered it is looked up (viaddfindVar
) in the value of the...
symbol in the evaluation frame.......的值是一个(特殊的)pairlist,其元素由特殊符号引用..1,..2,...具有DDVAL位设置:当遇到其中一个时,它被查找(通过ddfindVar)在评估框架中的...符号的值。
#2
5
To add to Gavin's answer:
添加到Gavin的答案:
They are also mentioned briefly in the help page for reserved words (?Reserved
).
它们也在保留字的帮助页面中简要提及(?保留)。
A really simple example of usage is
一个非常简单的使用示例是
f <- function(...) print(..1)
f(x = 99) #prints 99
f() #throws an error