rlang (version 0.2.2)

expr_label: Turn an expression to a label

Description

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.

Examples

Run this code
# NOT RUN {
# 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)
})))
# }

Run the code above in your browser using DataCamp Workspace