I want to be able to take the ellipsis ...
and use it in multiple child functions inside of a parent function. Doing so throws an error which is sensible as I am passing z
to fun1
which has no z
argument.
tester <- function(x, ...) {
list(a=x, b=fun1(...), c=fun2(...))
}
fun1 <- function(y) y * 6
fun2 <- function(z) z + 1
tester(z=4, y=5, x=6)
## > tester(z=4, y=5, x=6)
## Error in fun1(...) : unused argument (z = 4)
What is the most generalizable way to use arguments from an ellipsis in multiple child functions. Pretend the problem gets worse and we have 10000 child functions each getting different arguments from ...
. The desired output would be:
$a
[1] 6
$b
[1] 30
$c
[1] 5
I suspect it may be useful to capture the formals of each child function and match against the named arguments in ...
but that seems less generalizable (but that may be as good as it gets).