Skip to content

An ordered list is a container, see containers.

Usage

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

Arguments

items

If not NULL, then a character vector. Each element of the vector will be one list item, and the list container will be closed by default (see the .close argument).

id

Id of the list container. Can be used for closing it with cli_end() or in themes. If NULL, then an id is generated and returned invisibly.

class

Class of the list container. Can be used in themes.

.close

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

.auto_close

Whether to close the container, when the calling function finishes (or .envir is removed, if specified).

.envir

Environment to evaluate the glue expressions in. It is also used to auto-close the container if .auto_close is TRUE.

Value

The id of the new container element, invisibly.

Details

Adding all items at once

fun <- function() {
  cli_ol(c("one", "two", "three"))
}
fun()

#> 1. one                                                                          
#> 2. two                                                                          
#> 3. three                                                                        

Adding items one by one

## Adding items one by one
fun <- function() {
  cli_ol()
  cli_li("{.emph one}")
  cli_li("{.emph two}")
  cli_li("{.emph three}")
  cli_end()
}
fun()

#> 1. one                                                                          
#> 2. two                                                                          
#> 3. three                                                                        

Nested lists

fun <- function() {
  cli_div(theme = list(ol = list("margin-left" = 2)))
  cli_ul()
  cli_li("one")
  cli_ol(c("foo", "bar", "foobar"))
  cli_li("two")
  cli_end()
  cli_end()
}
fun()

#> • one                                                                           
#>     1. foo                                                                      
#>     2. bar                                                                      
#>     3. foobar                                                                   
#> • two