# NOT RUN {
# The advantage of expr() over quote() is that it unquotes on
# capture:
expr(list(1, !! 3 + 10))
# Unquoting can be especially useful for successive transformation
# of a captured expression:
(expr <- quote(foo(bar)))
(expr <- expr(inner(!! expr, arg1)))
(expr <- expr(outer(!! expr, !!! lapply(letters[1:3], as.symbol))))
# Unlike quo(), expr() produces expressions that can
# be evaluated with base::eval():
e <- quote(letters)
e <- expr(toupper(!!e))
eval(e)
# Be careful if you unquote a quosure: you need to take the RHS
# (and lose the scope information) to evaluate with eval():
f <- quo(letters)
e <- expr(toupper(!! get_expr(f)))
eval(e)
# On the other hand it's fine to unquote quosures if you evaluate
# with eval_tidy():
f <- quo(letters)
e <- expr(toupper(!! f))
eval_tidy(e)
# exprs() lets you unquote names with the definition operator:
nm <- "foo"
exprs(a = 1, !! nm := 2)
# }
Run the code above in your browser using DataLab