I'm trying to create dynamic SQL pulls in R. I'm using dplyr to create the pulls. However, I haven't found a way to properly convert a string to expression with dplyr.
For example, the following code will work.
data("CO2")
CO2_mod <- CO2 %>%
mutate(new_c = trimws(paste0(Plant, Type)))
However, when I try any of these below none of them will work. Does anyone know how to convert this string to something I can use in a dplyr pull.
command <- 'mutate(new_c = trimws(paste0(Plant, Type)))'
expr <- parse_expr(command)
expr <- str2lang(command)
expr <- str2expression(command)
CO2_mod <- CO2 %>%
expr #Tried this too for all combinations as well eval(expr)