I am trying to declare the variables inside mutate using all_of but not getting proper output
asd <- data.frame(Col1 = c("A","B"), Col2 = c("R","E"))
a1 <- "Col1"
When I perform below operations, I get invalid output
asd %>% mutate(q1 = case_when(all_of(a1) == "A" ~ 1))
Col1 Col2 a1
1 A R NA
2 B E NA
Expected Output
asd %>% mutate(q1 = case_when(Col1 == "A" ~ 1))
Col1 Col2 q1
1 A R 1
2 B E NA