I can use a variable to represent a column name in dplyr mutate, as long as it's on the right-hand side, in the calculation section. This works fine:
library(dplyr)
var <- "mass"
x <- starwars %>%
mutate(height = height * 2,
mass = get(var) * 2)
However, if I try to use a variable to represent a new column name (i.e., on the left-hand side), it throws an error. e.g, this leads to an error:
var <- "mass"
x <- starwars %>%
mutate(height = height * 2,
get(var) = get(var) * 2)
How do I use a variable as a column name in mutate?