You can do this using the !!
operator on the variable after call to sym
. This will unquote and evaluate variable
in the surrounding environement.
library(rlang)
g1 <- function( variable ) {
ggplot(mtcars, aes(x = wt, y = !! sym(variable) , size = "carb")) +
geom_point()
}
g1("mpg")
variables <- c("mpg", "cyl", "disp")
variables %>%
lapply(g1)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…