r - 两个点,R 中的 ".."

标签 r

这可能是一个蹩脚的问题,但无论如何。在 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/

相关文章:

R:如何在不使用循环的情况下对数据框中的前一行进行计算?

删除 ggpairs 中的密度轴文本

r - 将数据帧与数据帧列表相匹配,并将新变量添加到 R 中的列表中

r - R中一页上的多个图

r - Redshift 上的 Rmarkdown/knitr 中的 SQL block 是否支持 INNER JOIN 和通用表表达式?

r - 检测不同数据框中的字符串,从 R 中的列返回值

按两列排名并保持联系

rbind 单个数据框中每两列的完整行

r - 解析回 'messy' API 结构

r - 让 S4 对象充当 S3 类?