我很困惑 list(...)
适用于 R 和 S-plus。对于以下代码
pp <- function(x, ...) { print( length( list(...)))}
pp(1,,,1)
在 S-Plus 中,它有效,但在 R 中,它给出“
Error in print(length(list(...))) : argument is missing, with no default
”我更感兴趣的是它在 R 中的工作原理以及如何获得
list(...)
的值在 R 函数中。
最佳答案
我不确定为什么 S-plus 中允许使用该语法,而 R 中不允许。
不过,这里有一些 R 代码,它们具有基本相同的效果:
pp <- function(x, ...) {
print(length(as.list(match.call(expand.dots=FALSE))[["..."]]))
}
pp(1,,,1)
# [1] 3
或者,使用技巧 from here :
ppp <- function(x, ...) {
print(length(substitute(...())))
}
ppp(1,,,1)
# [1] 3
关于r - 如何在 R 和 S 函数中获取 list(...) 的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16972181/