This works as expected:
library(dplyr)
f <- function(x = c(am, vs))
mtcars %>%
select({{x}})
How would I rewrite the function (let's call it f2
) such that f2
selects only the first element of x, that is f2()
should eventually be the same as mtcars %>% select(am)
?
Some requirements:
- I do want to pass the columns as vector, thus a solution using
...
would not work in my case. - I want to stay inside the tidyverse syntax and want to pass unquoted column names, that is using
x = c("am", "vs")
is also not desired.
mtcars %>% select({{x}}) %>% select(1)
– Kalvn