I've learned from this answer that one way to pass multiple colnames to dplyr::select()
within a custom function is by using dot-dot-dot and rlang::enquos(...)
and finally !!!
in select()
.
library(dplyr, warn.conflicts = FALSE)
my_select_func <- function(data, ...) {
columns <- rlang::enquos(...)
data %>%
select(disp, !!!columns) # I want `disp` to always be included. Otherwise, I would've simply done `select(...)`
}
my_new_dat <- my_select_func(mtcars, am, mpg)
But I wonder if there's a more updated or "best practice" way to do this. Maybe using curly-curly syntax? i.e., {{
Thanks!