# The advantage of tidy_quote_expr() over quote() is that it unquotes on
# capture:
tidy_quote_expr(list(1, !! 3 + 10))
# Unquoting can be especially useful for successive transformation
# of a captured expression:
(expr <- quote(foo(bar)))
(expr <- tidy_quote_expr(inner(!! expr, arg1)))
(expr <- tidy_quote_expr(outer(!! expr, !!! lapply(letters[1:3], as.symbol))))
# Unlike tidy_quote(), tidy_quote_expr() produces expressions that can
# be evaluated with base::eval():
e <- quote(letters)
e <- tidy_quote_expr(toupper(!!e))
eval(e)
# Be careful if you unquote a formula-quote: you need to take the
# RHS (and lose the scope information) to evaluate with eval():
f <- ~letters
e <- tidy_quote_expr(toupper(!! f_rhs(f)))
eval(e)
# However it's fine to unquote formulas if you evaluate with tidy_eval():
f <- ~letters
e <- tidy_quote_expr(toupper(!! f))
tidy_eval(e)
Run the code above in your browser using DataCamp Workspace