Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/84.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R 如何在内部函数中重用参数?_R - Fatal编程技术网

R 如何在内部函数中重用参数?

R 如何在内部函数中重用参数?,r,R,我有一个函数do\u something,它接收四个参数并调用一个内部函数get\u options: do_something <- function(name, amount, manufacturer="abc", width=4){ opts <- get_options(amount, manufacturer = manufacturer, width = width) } get_options <- function(amount, manufact

我有一个函数
do\u something
,它接收四个参数并调用一个内部函数
get\u options

do_something <- function(name, amount, manufacturer="abc", width=4){ 
    opts <- get_options(amount, manufacturer = manufacturer, width = width)
}

get_options <- function(amount, manufacturer="abc", width = 4) { 
    opts <- validate_options(manufacturer, width)
}
dou\u something您可以使用省略号(
)并仅为最低级别的函数提供默认值:

do_something <- function(name, amount, ...){ 
    opts <- get_options(amount, ...)
}

get_options <- function(amount, manufacturer="abc", width = 4) { 
    opts <- validate_options(manufacturer, width)
}

同样的结果。

我很难在这里看到一个问题。你的例子并不特别有启发性
get_options(400)
get_options(400, manufacturer = "def")
do_something("A", 400)
do_something("A", 400, width=10)