19.2 Motivation

Simple concrete example:

cement() is a function that works like paste() but doesn’t need need quotes

(Think of automatically adding ‘quotes’ to the arguments)

cement <- function(...) {
  args <- ensyms(...)
  paste(purrr::map(args, as_string), collapse = " ")
}

cement(Good, morning, Hadley)
#> [1] "Good morning Hadley"

What if we wanted to use variables? What is an object and what should be quoted?

This is where ‘unquoting’ comes in!

name <- "Bob"
cement(Good, afternoon, !!name) # Bang-bang!
#> [1] "Good afternoon Bob"