使用以下函数foo()作为一个简单的例子...,如果可能的话,我想分发两个不同函数给出的值.
foo <- function(x, y, ...) {
list(sum = sum(x, ...), grep = grep("abc", y, ...))
}
Run Code Online (Sandbox Code Playgroud)
在下面的例子中,我希望na.rm传递给sum(),并value传递给grep().但是我在一个未使用的参数中得到一个错误grep().
X <- c(1:5, NA, 6:10)
Y <- "xyzabcxyz"
foo(X, Y, na.rm = TRUE, value = TRUE)
# Error in grep("abc", y, ...) : unused argument (na.rm = TRUE)
Run Code Online (Sandbox Code Playgroud)
看起来这些论点grep()首先被发送出去了.那是对的吗?我认为R会sum()首先看到并评估,并为该情况返回错误.
此外,当试图分裂论点时...,我遇到了麻烦. sum()正式的论据是NULL因为它是一个.Primitive,因此我无法使用
names(formals(sum)) %in% names(list(...))
Run Code Online (Sandbox Code Playgroud)
我也不想假设剩下的论据来自
names(formals(grep)) %in% …Run Code Online (Sandbox Code Playgroud) r ×1