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)