expr_label.Rdexpr_find() finds the full expression; expr_text() turns the
expression into a single string; expr_label() formats it nicely for
use in messages. expr_env() finds the environment associated with
the expression.
expr_label(x)
expr_text(x, width = 60L, nlines = Inf)
expr_find(x)
expr_env(x, default_env)These functions never force promises, and will work even if a promise has previously been forced.
# Unlike substitute(), expr_find() finds the original expression
f <- function(x) g(x)
g <- function(y) h(y)
h <- function(z) list(substitute(z), expr_find(z))
f(1 + 2 + 3)
#> [[1]]
#> y
#>
#> [[2]]
#> 1 + 2 + 3
#>
expr_label(10)
#> [1] "10"
# Names a quoted with ``
expr_label(x)
#> [1] "`x`"
# Strings are encoded
expr_label("a\nb")
#> [1] "\"a\\nb\""
# Expressions are captured
expr_label(a + b + c)
#> [1] "`a + b + c`"
# Long expressions are collapsed
expr_label(foo({
1 + 2
print(x)
}))
#> [1] "`foo(...)`"