r-lib/cli

Feature Request: Collapse a character vector like `glue::glue_collapse()`

Closed this issue · 2 comments

Hello,

When a character vector is collapsed, I would like an argument to pass along a string to use to separate the last two items (when they are at least two elements in the character vector). At this moment "and" is used and I cannot find a way to change it. The expected behavior would be similar to glue::glue_collapse().

For example:

cli::cli_inform("Choose either: {.code {LETTERS[1:4]}}")
#> Choose either: `A`, `B`, `C`, and `D`

changed to:

cli::cli_inform("Choose either: {.code {LETTERS[1:4]}}", .last = " or ")
#> Choose either: `A`, `B`, `C`, or `D`

The current work around is, which works but isn't elegant:

cli::cli_inform('Choose either: {.code {glue::glue_collapse(LETTERS[1:4], sep = ", ", last = " or ")}}')
#> Choose either: `A, B, C or D`

Thank you.

❯ cli::cli_inform("Choose either: {.or {.code {LETTERS[1:4]}}}")
Choose either: `A`, `B`, `C`, or `D`

Thank you @gaborcsardi ! I see now that it is mentioned in the inline markup vignette. I will be closing this issue. Thank you again.