cli_vec: Add custom cli style to a vector

View source: R/format.R

cli_vecR Documentation

Add custom cli style to a vector

Description

Add custom cli style to a vector

Usage

cli_vec(x, style = list())

Arguments

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.

Details

You can use this function to change the default parameters of collapsing the vector into a string, see an example below.

The style is added as an attribute, so operations that remove attributes will remove the style as well.

Custom collapsing separator

v <- cli_vec(
  c("foo", "bar", "foobar"),
  style = list("vec-sep" = " & ", "vec-last" = " & ")
)
cli_text("My list: {v}.")
#> My list: foo & bar & foobar.                                                    

Custom truncation

x <- cli_vec(names(mtcars), list("vec-trunc" = 3))
cli_text("Column names: {x}.")
#> Column names: mpg, cyl, disp, …, gear, and carb.                                

See Also

cli_format()


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