参考:https://www.jianshu.com/p/7a3d027258bb
我们可以通过省略号,来定义一个不定长的参数。
> v <- c(sqrt(1:100))> f <- function(x, ...) { print(x); summary(...)}> f("Here is the summary for v.", v, digits=2)[1] "Here is the summary for v."Min. 1st Qu. Median Mean 3rd Qu. Max.1.0 5.1 7.1 6.7 8.7 10.0
此时,… 中的内容都会被传入summary 函数当中。
但是,如果我们希望对… 中的所有参数分别处理呢?
这时候我们需要做的是在函数内部将对象…转换为一个列表。
> addemup <- function(x, ...){+ args <- list(...)+ for (a in args) x <- x + a+ x+ }
