R's dots (i.e. ellipsis) are great for wring general-purpose wrapper functions, e.g.:
wrapper_f <- function(x, ...) {
x <- some_transform(x)
inner_f(x, ...)
}
But when your wrapper wraps more than one inner function, the dots args can lead to confusion since some of the wrong (or at least un-expected) additional arguments are sent to each inner function:
wrapper_f <- function(x, ...) {
x <- some_transform(x)
x <- inner_f1(x, ...)
inner_f2(x, ...)
}
So when this issue comes around, I usually end up modifying the wrapper function to take not dots, but rather separate lists for args to pass to the inner functions, like so:
wrapper_f <- function(x, inner_f1_args = list(), inner_f2_args = list()) {
x <- some_transform(x)
x <- do.call(inner_f1, c(list(x = x), inner_f1_args))
do.call(inner_f2, c(list(x = x), inner_f2_args))
}
This works, but mixing the dots paradigm with this 'list' paradigm (just when the wrapper function happens to wrap one vs many underlying functions) is somehow inelegant to me. How do the rest of you handle this nicely? Perhaps some rlang patterns of which I'm not yet aware?