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:
purrr::partial looks like exactly what I was looking for, thanks!
The tidyeval part doesn't quite match what I'm doing, I'm passing the parameters as strings, not object names (because I can loop over a vector of strings more easily, say for example if read in from a CSV specifying the job).
It took me a minute to figure out why scale_fn_name was working unquoted - it is because match.fun also accepts functions and simply returns them - but I need it to be able to work with quoted names. The function calls look more like this:
my_graph_maker(my_dat, 'Income', 'dollar')
Although I am not actually literally typing those strings, they come from the vectors I'm looping over.
But, the tidyeval part is beyond the scope for this question, I can climb that hill another day. Thank you for pointing out purrr::partial, I wasn't searching the right things to find that one!