Skip to contents

These are wrapped versions of cli methods. The wrapper inserts a condition handler that produces log data.

Usage

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

cli_alert(text, id = NULL, class = NULL, wrap = FALSE, .envir = parent.frame())

cli_alert_danger(
  text,
  id = NULL,
  class = NULL,
  wrap = FALSE,
  .envir = parent.frame()
)

cli_alert_info(
  text,
  id = NULL,
  class = NULL,
  wrap = FALSE,
  .envir = parent.frame()
)

cli_alert_success(
  text,
  id = NULL,
  class = NULL,
  wrap = FALSE,
  .envir = parent.frame()
)

cli_alert_warning(
  text,
  id = NULL,
  class = NULL,
  wrap = FALSE,
  .envir = parent.frame()
)

cli_blockquote(
  quote,
  citation = NULL,
  id = NULL,
  class = NULL,
  .envir = parent.frame()
)

cli_bullets(text, id = NULL, class = NULL, .envir = parent.frame())

cli_bullets_raw(text, id = NULL, class = NULL)

cli_code(
  lines = NULL,
  ...,
  language = "R",
  .auto_close = TRUE,
  .envir = environment()
)

cli_div(
  id = NULL,
  class = NULL,
  theme = NULL,
  .auto_close = TRUE,
  .envir = parent.frame()
)

cli_dl(
  items = NULL,
  labels = names(items),
  id = NULL,
  class = NULL,
  .close = TRUE,
  .auto_close = TRUE,
  .envir = parent.frame()
)

cli_end(id = NULL)

cli_h1(text, id = NULL, class = NULL, .envir = parent.frame())

cli_h2(text, id = NULL, class = NULL, .envir = parent.frame())

cli_h3(text, id = NULL, class = NULL, .envir = parent.frame())

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

cli_li(
  items = NULL,
  labels = names(items),
  id = NULL,
  class = NULL,
  .auto_close = TRUE,
  .envir = parent.frame()
)

cli_ol(
  items = NULL,
  id = NULL,
  class = NULL,
  .close = TRUE,
  .auto_close = TRUE,
  .envir = parent.frame()
)

cli_progress_message(
  msg,
  current = TRUE,
  .auto_close = TRUE,
  .envir = parent.frame(),
  ...
)

cli_progress_output(text, id = NULL, .envir = parent.frame())

cli_progress_step(
  msg,
  msg_done = msg,
  msg_failed = msg,
  spinner = FALSE,
  class = if (!spinner) ".alert-info",
  current = TRUE,
  .auto_close = TRUE,
  .envir = parent.frame(),
  ...
)

cli_rule(
  left = "",
  center = "",
  right = "",
  id = NULL,
  .envir = parent.frame()
)

cli_text(..., .envir = parent.frame())

cli_ul(
  items = NULL,
  id = NULL,
  class = NULL,
  .close = TRUE,
  .auto_close = TRUE,
  .envir = parent.frame()
)

cli_vec(x, style = list())

cli_verbatim(..., .envir = parent.frame())

cli_warn(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.

text

Text of the alert.

id

Id of the alert element. Can be used in themes.

class

Class of the alert element. Can be used in themes.

wrap

Whether to auto-wrap the text of the alert.

quote

Text of the quotation.

citation

Source of the quotation, typically a link or the name of a person.

lines

Character vector, each line will be a line of code, and newline characters also create new lines. Note that no glue substitution is performed on the code.

language

Programming language. This is also added as a class, in addition to code.

.auto_close

Passed to cli_div() when creating the container of the code. By default the code container is closed after emitting lines and ... via cli_verbatim(). You can keep that container open with .auto_close and/or .envir, and then calling cli_verbatim() to add (more) code. Note that the code will be formatted and syntax highlighted separately for each cli_verbatim() call.

theme

A custom theme for the container. See themes.

items

Named character vector, or NULL. If not NULL, they are used as list items.

labels

Item labels. Defaults the names in items.

.close

Whether to close the list container if the items were specified. If FALSE then new items can be added to the list.

msg

Message to show. It may contain glue substitution and cli styling. It can be updated via cli_progress_update(), as usual.

current

Passed to cli_progress_bar().

msg_done

Message to show on successful termination. By default this it is the same as msg and it is styled as a cli success alert (see cli_alert_success()).

msg_failed

Message to show on unsuccessful termination. By default it is the same as msg and it is styled as a cli danger alert (see cli_alert_danger()).

spinner

Whether to show a spinner at the beginning of the line. To make the spinner spin, you'll need to call cli_progress_update() regularly.

left

Label to show on the left. It interferes with the center label, only at most one of them can be present.

center

Label to show at the center. It interferes with the left and right labels.

right

Label to show on the right. It interferes with the center label, only at most one of them can be present.

x

Vector that will be collapsed by cli.

style

Style to apply to the vector. It is used as a theme on a span element that is created for the vector. You can set vec-sep and vec-last to modify the separator and the last separator.

Value

The id of the container that contains the code.

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.