I have a function in R with a lot of default arguments, that I want to use multiple times. I want to be able to change those without having to write it all the time.
This is easy in Python like this:
def f(x, y, optional1=1, optional2=2, optional3=3):
return (x+y+optional1+optional2+optional3)
args = (10, 20)
print(f(1,2, *args)) #this prints 36 = 1+2+10+20+3
now I have an R function f = function(x,y, optional1=1, optional2=2, optional3=3) but I have not found a way of doing something similar to the example above.
I was hoping something could be done with the ellipsis (...) but seems like that's only for a variable amount of arguments in the function definition.
Doing something like
g = function(x,y){
return(f(x,y, 10, 20, 30)
}
would work but I was wondering if there was a cleaner and more readable way of doing this.
Thanks.