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

quo_squash

Squash a quosure


Description

quo_squash() flattens all nested quosures within an expression. For example it transforms ^foo(^bar(), ^baz) to the bare expression foo(bar(), baz).

This operation is safe if the squashed quosure is used for labelling or printing (see quo_label() or quo_name()). However if the squashed quosure is evaluated, all expressions of the flattened quosures are resolved in a single environment. This is a source of bugs so it is good practice to set warn to TRUE to let the user know about the lossy squashing.

Usage

quo_squash(quo, warn = FALSE)

Arguments

quo

A quosure or expression.

warn

Whether to warn if the quosure contains other quosures (those will be collapsed). This is useful when you use quo_squash() in order to make a non-tidyeval API compatible with quosures. In that case, getting rid of the nested quosures is likely to cause subtle bugs and it is good practice to warn the user about it.

Life cycle

This function replaces quo_expr() which was deprecated in rlang 0.2.0. quo_expr() was a misnomer because it implied that it was a mere expression acccessor for quosures whereas it was really a lossy operation that squashed all nested quosures.

Examples

# Quosures can contain nested quosures:
quo <- quo(wrapper(!!quo(wrappee)))
quo

# quo_squash() flattens all the quosures and returns a simple expression:
quo_squash(quo)

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.