我有一个do_something
接收四个参数并调用内部函数的函数get_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)
}
有时我会这样做get_options(400)
,有时我想覆盖参数get_options(400, manufacturer = "def")
,有时我会调用do_something("A", 400)
或do_something("A", 400, width=10)
.
通过在两个函数中为我的参数指定相同的默认值,我似乎是多余的。有没有更好的方法让他们共享这些默认值?