r – use string content of a variable to refer to a column in a dataframe using transmute dplyr


I would like to use the variable “second_column” as a variable to refer to the column “test1$b”. I tried different things, but couldn’t find any solutions yet. test1 and test2 should be the same in the end…

test1 <- data.frame(a = 1:5, b = 6:10)

second_column = "b"

test2 <- test1 %>% 
  transmute(variable1 = a,
         variable2 = second_column
  )

test1
test2