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

expr_label

Turn an expression to a label


Description

Questioning lifecycle

expr_text() turns the expression into a single string, which might be multi-line. expr_name() is suitable for formatting names. It works best with symbols and scalar types, but also accepts calls. expr_label() formats the expression nicely for use in messages.

Usage

expr_label(expr)

expr_name(expr)

expr_text(expr, width = 60L, nlines = Inf)

Arguments

expr

An expression to labellise.

width

Width of each line.

nlines

Maximum number of lines to extract.

Life cycle

These functions are in the questioning stage because they are redundant with the quo_ variants and do not handle quosures.

Examples

# To labellise a function argument, first capture it with
# substitute():
fn <- function(x) expr_label(substitute(x))
fn(x:y)

# Strings are encoded
expr_label("a\nb")

# Names and expressions are quoted with ``
expr_label(quote(x))
expr_label(quote(a + b + c))

# Long expressions are collapsed
expr_label(quote(foo({
  1 + 2
  print(x)
})))

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.