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

set_expr

Set and get an expression


Description

These helpers are useful to make your function work generically with quosures and raw expressions. First call get_expr() to extract an expression. Once you're done processing the expression, call set_expr() on the original object to update the expression. You can return the result of set_expr(), either a formula or an expression depending on the input type. Note that set_expr() does not change its input, it creates a new object.

Usage

set_expr(x, value)

get_expr(x, default = x)

Arguments

x

An expression, closure, or one-sided formula. In addition, set_expr() accept frames.

value

An updated expression.

default

A default expression to return when x is not an expression wrapper. Defaults to x itself.

Value

The updated original input for set_expr(). A raw expression for get_expr().

See Also

quo_get_expr() and quo_set_expr() for versions of get_expr() and set_expr() that only work on quosures.

Examples

f <- ~foo(bar)
e <- quote(foo(bar))
frame <- identity(identity(ctxt_frame()))

get_expr(f)
get_expr(e)
get_expr(frame)

set_expr(f, quote(baz))
set_expr(e, quote(baz))

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.