format_error {cli}R Documentation

Format an error, warning or diagnostic message

Description

You can then throw this message with stop() or rlang::abort().

Usage

format_error(message, .envir = parent.frame())

format_warning(message, .envir = parent.frame())

format_message(message, .envir = parent.frame())

Arguments

message

It is formatted via a call to cli_bullets().

.envir

Environment to evaluate the glue expressions in.

Details

The messages can use inline styling, pluralization and glue substitutions.

Examples

## Not run: 
n <- "boo"
stop(format_error(c(
        "{.var n} must be a numeric vector",
  "x" = "You've supplied a {.cls {class(n)}} vector."
)))

len <- 26
idx <- 100
stop(format_error(c(
        "Must index an existing element:",
  "i" = "There {?is/are} {len} element{?s}.",
  "x" = "You've tried to subset element {idx}."
)))

## End(Not run)

[Package cli version 3.0.1 Index]