data-mask -> selection, via transmute
transmute()
creates a data frame that consists of columns in...
names()
yields a character vector of column names from...
all_of()
accepts a character vector of names and performs tidy selection
my_pivot_longer <- function(data, ...) {
# Forward `...` in data-mask context with `transmute()`
# and save the inputs names
inputs <- dplyr::transmute(data, ...)
names <- names(inputs)
# Update the data with the inputs
data <- dplyr::mutate(data, !!!inputs)
# Select the inputs by name with `all_of()`
tidyr::pivot_longer(data, cols = all_of(names))
}
mtcars %>% my_pivot_longer(cyl, am = am * 100)