这可能是一个蹩脚的问题,但无论如何。在 RStudio 中,我只是注意到输入一个数字 .. 和另一个数字会将字符的语法突出显示从海军蓝更改为 .. 和后面的数字的淡蓝色。
例如,这是一个具有这种独特颜色的数字:
4..4
“..4”部分为淡蓝色。
我正在使用默认的语法着色。我尝试在解释器中引入这样的常量,但我只收到错误“错误:“4..5”中的意外数字常量,并且带有“两个点”或 .. 的查询似乎对谷歌不太友好。
有谁知道“..”的用法是什么,如果有的话?
最佳答案
..4
将是 R 解析器中的保留字。下 ?Reserved
你会找到
...
and..1
,..2
etc, which are used to refer to arguments passed down from a calling function.
例子
# Function will return nth element from ... ( n MUST be a named argument)
f <- function( ... , n = NULL )
return( eval( parse( text = paste0( ".." , n ) ) ) )
# Return third element of ...
f( n = 3 , 1:3 , 3:1 , 10:15 )
#[1] 10 11 12 13 14 15
# Try to return element that is out of bounds
f( n = 4 , 1:3 , 3:1 , 10:15 )
#Error in eval(expr, envir, enclos) :
# the ... list does not contain 4 elements
现在你知道它是什么,你如何使用它?由约翰钱伯斯提供;"The name
..1
refers to the first matching argument,..2
to the second, etc. You should probably avoid this obscure convention, which can usually be done by writing a function with some ordinary argument names, and calling it with"..."
"Software for Data Analysis: Programming with R, John M. Chambers, Springer-Verlag, New York, 2008.
Excerpt from page 457.
关于r - 两个点,R 中的 "..",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19997231/