Hi all,
I have a program with many graph-making functions that encapsulate a lot of complexity. This makes it easier to loop over a large number of graphs that need generated. I pass to these functions (among other things) the name of a scale function. The scale function is one of three from the scales package: comma, dollar, or percent. I use match.fun to convert the string to the needed function.
This mostly works well, but the default behavior of the accuracy parameter of the scales functions is not behaving like I want, and I would like to set a value for it. Is there a simple way to pass a parameter value while using something like match.fun?
A simplified version of what I'm doing looks like this:
scale_fn_name <- 'percent' # actually is passed as a function parameter
scale_fn <- match.fun(scale_fn_name) # somewhere in the function body
And unfortunately this doesn't work because match.fun doesn't have an ... argument:
scale_fn <- match.fun(scale_fn_name, accuracy = 1)
The workaround I have now is to redefine the functions with the desired defaults, e.g.:
percent <- function(x, ...) {
scales::percent(x, accuracy = 1, ...)
}
Is there a better way?