In dplyr verbs, I understand how to unquote a column name given as a character in the environment:
var <- "height"
starwars %>%
transmute(test = !!sym(var))
# or
starwars %>%
transmute(test = .data[[var]])
But what if the column name is given in another column in the same tibble? E.g.:
starwars %>%
mutate(selected.var = "height") %>%
transmute(test = !!sym(selected.var))
# Error in is_symbol(x) : object 'selected.var' not found
(Intended output would be the same as the two examples above.) I don't see this use-case covered in the programming vignette, and I'm seeing that the tidyeval book is no longer current. Apologies if I've missed this in the documentation.
You're not reproducing the error for the final command? I omitted the output from the first block of code for brevity's sake since there is no error and it is working as intended.
Yes, I'm using 1.0.5.
Thanks. I did use reprex - I just shortened the output afterward.
In my actual use-case, I really need to have selected.var be a column within the tibble, because it can vary. So it cannot be a static variable in the environment.