Is it possible to change the default values of formal parameters in an R function at runtime?
Let's assume, we have the function
f <- function(x=1) {
...
}
can I somehow change the default value of x from 1 to, say, 2?
Thanks in advance,
Sven
An alternative (shown in a different SO post) is to use the
formals
function, e.g.:formals(f) <- 2
As the Defaults package is no longer available from CRAN, you can use default.
As an example:
Created on 2019-03-22 by the reprex package (v0.2.0.9000).
Yes, the Defaults package allows you to do this.