rlang (version 0.0.0.9000)

tidy_quote_expr: Untidy quotation of an expression.

Description

Unlike tidy_quote(), tidy_quote_expr() returns a raw expression instead of a formula. As a result, tidy_quote_expr() is untidy in the sense that it does not preserve scope information for the quoted expression. It can still be useful in certain cases. Compared to base R's quote(), it unquotes the expression on capture, and compared to tidy_quote(), the quoted expression is directly compatible with the base R eval() function.

Usage

tidy_quote_expr(expr)

Arguments

expr
An expression.

Value

The raw expression supplied as argument.

See Also

See tidy_quote() and tidy_interp() for more explanation on tidy quotation.

Examples

Run this code
# 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