【发布时间】:2012-12-04 00:57:18
【问题描述】:
有没有办法“访问”函数中所有传递的参数?我相信这可以通过 arguments 数组在 javascript 中完成,R 中是否有等价物?
myfunc <- function() {
print(arguments[1])
print(arguments[2])
}
R> myfunc("A","B")
[1] "A"
[1] "B"
【问题讨论】:
标签: r
有没有办法“访问”函数中所有传递的参数?我相信这可以通过 arguments 数组在 javascript 中完成,R 中是否有等价物?
myfunc <- function() {
print(arguments[1])
print(arguments[2])
}
R> myfunc("A","B")
[1] "A"
[1] "B"
【问题讨论】:
标签: r
从技术上讲,您的函数没有参数,因此将参数传递给它是错误的。
也就是说,您至少需要...。如果你这样做了,你可以在... 上使用list,然后访问... 的副本 的名称。例如:
myfunc <- function(...) {
names(list(...))
}
另一种方法是使用match.call 解析调用。例如:
myfunc <- function(A, B) {
names(match.call()[-1])
}
【讨论】: