I have a function
somefun <- function(someparameters , ...) { plot(stuff, ...)}
Now I would like to provide some defaults for plot in the case that the user hasn't specified those arguments. (i.e. xlab=""
).
How do I provide a set of default plot options but still allow the user to override those arguments? Since if the same argument is inputted twice, R will throw the error: formal argument matched by multiple actual arguments.
I am aware that I can pass on all these options through my function
somefun <- function(someparameters, main, xlab, ylab, xlim....)
but I would rather not do that.
Is there some easy neat solution to achieve this?
Try modifyList
used as follows:
f <- function(x, ...) {
defaults <- list(xlab = "x", ylab = "y")
args <- modifyList(defaults, list(x = x, ...))
do.call("plot", args)
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With