I have been trying to understand tidy eval or how to use variables within tidyverse for a while, but I never seem to fully grasp it.
For example, I am trying to use ggplot with variable mappings. This would the base R version:
library(ggplot2)
var1 = "wt"
var2 = "mpg"
ggplot(mtcars, aes(x = get(var1), y = get(var2))) + geom_point()
However, based on all the documentation and discussion I have seen, the "proper" quasiquotation way would be:
ggplot(mtcars, aes(x = !!sym(var1), y = !!sym(var2))) + geom_point()
Maybe that is more comparable to:
ggplot(mtcars, aes(x = !!as.symbol(var1), y = !!as.symbol(var2))) + geom_point()
The get()
method is shorter and more readable to me. Why is it shunned by the tidyverse community?