foo <- function(x, a = 5, ...) {
foo1 <- function(x, b = 5) return(b)
c(a = a, b = foo1(x, ...), x = x)
}
foo(1)
f <- setargs(foo, a = 10) # set new default value for a
f(1)
# default value of b in lower-level function is unaffected and warning is
# cast to inform that b is not an argument in f
f <- setargs(foo, b = 10)
f(1)
# disable warning message
setargs(foo, b = 10, setargs.warn = FALSE)(1)
# arguments of lower-level functions can be set with setallargs
f <- setallargs(foo, a = 10, b = 10)
f(1)
# does not work when `missing` checks for missing formal arguments.
foo1 <- function(x, a) {
if (missing(a)) a <- 5
return(c(x = x, a = a))
}
f <- setargs(foo1, a = 10)
f(1)
Run the code above in your browser using DataLab