cli_abort: Signal an error, warning or message with a cli formatted...

View source: R/rlang.R

cli_abortR Documentation

Signal an error, warning or message with a cli formatted message

Description

These functions let you create error, warning or diagnostic messages with cli formatting, including inline styling, pluralization and glue substitutions.

Usage

cli_abort(
  message,
  ...,
  call = .envir,
  .envir = parent.frame(),
  .frame = .envir
)

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

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

Arguments

message

It is formatted via a call to cli_bullets().

...

Passed to rlang::abort(), rlang::warn() or rlang::inform().

call

The execution environment of a currently running function, e.g. call = caller_env(). The corresponding function call is retrieved and mentioned in error messages as the source of the error.

You only need to supply call when throwing a condition from a helper function which wouldn't be relevant to mention in the message.

Can also be NULL or a defused function call to respectively not display any call or hard-code a code to display.

For more information about error calls, see Including function calls in error messages.

.envir

Environment to evaluate the glue expressions in.

.frame

The throwing context. Used as default for .trace_bottom, and to determine the internal package to mention in internal errors when .internal is TRUE.

Details

n <- "boo"
cli_abort(c(
        "{.var n} must be a numeric vector",
  "x" = "You've supplied a {.cls {class(n)}} vector."
))
#> Error:                                                                          
#> ! `n` must be a numeric vector                                                  
#>  You've supplied a <character> vector.                                         
#> Run `rlang::last_error()` to see where the error occurred.                      
len <- 26
idx <- 100
cli_abort(c(
        "Must index an existing element:",
  "i" = "There {?is/are} {len} element{?s}.",
  "x" = "You've tried to subset element {idx}."
))
#> Error:                                                                          
#> ! Must index an existing element:                                               
#>  There are 26 elements.                                                        
#>  You've tried to subset element 100.                                           
#> Run `rlang::last_error()` to see where the error occurred.                      

See Also

These functions support inline markup.

Other functions supporting inline markup: cli_alert(), cli_blockquote(), cli_bullets_raw(), cli_bullets(), cli_dl(), cli_h1(), cli_li(), cli_ol(), cli_process_start(), cli_progress_along(), cli_progress_bar(), cli_progress_message(), cli_progress_output(), cli_progress_step(), cli_rule, cli_status_update(), cli_status(), cli_text(), cli_ul(), format_error(), format_inline()


cli documentation built on June 22, 2024, 10:57 a.m.