【发布时间】:2019-04-10 15:54:01
【问题描述】:
在 R 文档中,它解释说
参数“...”可用于允许一个函数将参数设置传递给另一个函数。
我不太确定它是如何工作的......在我的想象中它会像这样工作:
Arithmetic <- function(x, ...) {
calculate <- function(x, y = 1, operand = "add") {
if (operand == "add") {return(x + y)}
if (operand == "subtract") {return(x - y)}
if (operand == "multiply") {return(x * y)}
if (operand == "devide") {return(x / y)}
}
return(calculate(x, y, operand))
}
Arithmetic(x = 3, y = 4, operand = "subtract")
## [1] -1
而发生的事情是:
Error in calculate(x, y, operand) : object 'operand' not found
那么... 究竟是如何在 R 中用于用户定义的函数的?
【问题讨论】:
标签: r function nested arguments user-defined-functions