Adapted from Tidy evaluation with rlang cheat sheet
library(rlang)
Sometimes a variable name has a value in the global environment and is the name of a variable inside of a data frame (try to avoid having this happen, it’s confusing).
# variables in global env
a <- "life"
b <- "line"
stringr::str_c(a, b)
## [1] "lifeline"
# one row data frame
mydat <- tibble::tibble(a = "coast", b = "guard")
mydat
## # A tibble: 1 x 2
## a b
## <chr> <chr>
## 1 coast guard
# the experssion we'll evaluate, quoted to use later as a quosure
p <- quo(stringr::str_c(.data$a,!!b))
# using `eval_tidy()`
eval_tidy(p, data = mydat)
## [1] "coastline"
# the experssion we'll evaluate, quoted to use later as a quosure
q <- quo(stringr::str_c(!!a, .data$b))
# using `eval_tidy()`
eval_tidy(q, data = mydat)
## [1] "lifeguard"