as_quosure {rlang}R Documentation

Coerce object to quosure

Description

Quosure objects wrap an expression with a lexical enclosure. This is a powerful quoting (see base::quote() and quo()) mechanism that makes it possible to carry and manipulate expressions while making sure that its symbolic content (symbols and named calls, see is_symbolic()) is correctly looked up during evaluation.

Usage

as_quosure(x, env = caller_env())

as_quosureish(x, env = caller_env())

Arguments

x

An object to convert.

env

An environment specifying the lexical enclosure of the quosure.

See Also

is_quosure()

Examples

# Sometimes you get unscoped formulas because of quotation:
f <- ~~expr
inner_f <- f_rhs(f)
str(inner_f)
is_quosureish(inner_f, scoped = TRUE)

# You can use as_quosure() to provide a default environment:
as_quosure(inner_f, base_env())

# Or convert expressions or any R object to a validly scoped quosure:
as_quosure(quote(expr), base_env())
as_quosure(10L, base_env())


# While as_quosure() always returns a quosure (one-sided formula),
# as_quosureish() returns quosureish objects:
as_quosure(a := b)
as_quosureish(a := b)
as_quosureish(10L)

[Package rlang version 0.1.1 Index]