Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

as_quosure

Coerce object to quosure


Description

While new_quosure() wraps any R object (including expressions, formulas, or other quosures) into a quosure, as_quosure() converts formulas and quosures and does not double-wrap.

Usage

as_quosure(x, env = NULL)

new_quosure(expr, env = caller_env())

Arguments

x

An object to convert. Either an expression or a formula.

env

The environment in which the expression should be evaluated. Only used for symbols and calls. This should typically be the environment in which the expression was created.

expr

The expression wrapped by the quosure.

Life cycle

  • as_quosure() now requires an explicit default environment for creating quosures from symbols and calls.

  • as_quosureish() is deprecated as of rlang 0.2.0. This function assumes that quosures are formulas which is currently true but might not be in the future.

See Also

Examples

# as_quosure() converts expressions or any R object to a validly
# scoped quosure:
env <- env(var = "thing")
as_quosure(quote(var), env)


# The environment is ignored for formulas:
as_quosure(~foo, env)
as_quosure(~foo)

# However you must supply it for symbols and calls:
try(as_quosure(quote(var)))

rlang

Functions for Base Types and Core R and 'Tidyverse' Features

v0.4.11
MIT + file LICENSE
Authors
Lionel Henry [aut, cre], Hadley Wickham [aut], mikefc [cph] (Hash implementation based on Mike's xxhashlite), Yann Collet [cph] (Author of the embedded xxHash library), RStudio [cph]
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.