Here's a simplified version of a function I have in a package that uses the ...
argument and tidyselect
to select variables:
# this toy function just selects the ... variables
foo <- function(dat = mtcars, ...){
expr <- rlang::expr(c(...))
cols_to_select <- tidyselect::eval_select(expr, data = dat)
dplyr::select(dat, all_of(cols_to_select))
}
This works: foo(mtcars, cyl)
But my actual function has more preceding arguments before the ...
argument, all with default values. It's tedious to type them all in cases where I call my function with those default values and pass a value to ...
.
This is what I want - to assume dat = mtcars
- but it does not work:
foo(... = cyl)
Error: Names must not be of the form
...
or..j
.
Can I modify either the function or the call to allow direct specification of ...
?