I have a function like
myfunc <- function(x, y=x){
x+y
}
which (obviously) defaults the value of y to x if y is not passed to the function.
Now, I'm using optparse
to read some command line arguments to a script which calls myfunc
.
# myscript.R
option_list <- list(
make_option(c("--x"), type="numeric"),
make_option(c("--y"), type="numeric")
)
print(myfunc(opt$x, opt$y))
The problem with the code above is, it forces the user to provide a value for y (otherwise an error will be thrown). Instead, I'd like to call myfunc
using all and only the parameters provided by the user. How can I accomplish this in the most elegant, scalable, generalize-able way?
Note - for those familiar with Python, I think I want do something similar to dictionary unpacking using whatever values are inside opt
.