cli_format: Format a value for printing

Description Usage Arguments Details See Also Examples

View source: R/format.R

Description

This function can be used directly, or via the {.val ...} inline style. {.val {expr}} calls cli_format() automatically on the value of expr, before styling and collapsing it.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
cli_format(x, style = NULL, ...)

## Default S3 method:
cli_format(x, style = NULL, ...)

## S3 method for class 'character'
cli_format(x, style = NULL, ...)

## S3 method for class 'numeric'
cli_format(x, style = NULL, ...)

Arguments

x

The object to format.

style

List of formatting options, see the individual methods for the style options they support.

...

Additional arguments for methods.

Details

It is possible to define new S3 methods for cli_format and then these will be used automatically for {.val ...} expressions.

See Also

cli_vec()

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
things <- c(rep("this", 3), "that")
cli_format(things)
cli_text("{.val {things}}")

nums <- 1:5 / 7
cli_format(nums, style = list(digits = 2))
cli_text("{.val {nums}}")
divid <- cli_div(theme = list(.val = list(digits = 3)))
cli_text("{.val {nums}}")
cli_end(divid)

RonMobile/cli documentation built on Dec. 18, 2021, 11 a.m.