Changing default arguments for function R at runtime

Is it possible to change the default values โ€‹โ€‹of formal parameters in an R function at run time?

Suppose we have a function

f <- function(x=1) { ... } 

Is there any way to change the default value of x from 1 to, say, 2?


Thanks in advance,
Sven

+7
source share
2 answers

Yes, the Defaults package allows you to do this.

+4
source

An alternative (shown in another SO post ) is to use the formals function, for example:

formals(f) <- 2

0
source

All Articles