So I've found many times various different ways to achieve this, but as of the past year or so there have been changes to the way dplyr handles non standard evaluation. Essentially one way to achieve this is as follows:
require("dplyr") test <- function(var){ mtcars %>% select({{var}}) print(quo_name(enquo(var))) } test(wt) #> [1] "wt"
Is there a more direct way to achieve this as of 2021? I could have sworn there was something much simpler.
Use ensym() from rlang:
ensym()
rlang
require("dplyr") require("rlang") test <- function(var){ mtcars %>% select({{var}}) print(ensym(var)) } test(wt) #>wt as.character(test(wt)) #>wt #>[1] "wt"
2.1m questions
2.1m answers
60 comments
57.0k users