From c9d26d6659161d237fe4d7dc212bf8ac109513fd Mon Sep 17 00:00:00 2001 From: Colin Rundel Date: Thu, 15 Aug 2024 10:34:06 -0700 Subject: [PATCH 1/7] Handle NA, NaN, Inf and -Inf edge cases --- R/pluralize.R | 17 +++-- tests/testthat/_snaps/pluralization.md | 93 ++++++++++++++++++++++++++ tests/testthat/test-pluralization.R | 41 ++++++++++++ 3 files changed, 146 insertions(+), 5 deletions(-) diff --git a/R/pluralize.R b/R/pluralize.R index 2f13f7ce5..68b82f08c 100644 --- a/R/pluralize.R +++ b/R/pluralize.R @@ -9,7 +9,11 @@ NULL make_quantity <- function(object) { val <- if (is.numeric(object)) { stopifnot(length(object) == 1) - as.integer(object) + + if (is.finite(object)) + as.integer(object) + else + object } else { length(object) } @@ -87,13 +91,16 @@ process_plural <- function(qty, code) { parts <- strsplit(str_tail(code), "/", fixed = TRUE)[[1]] if (last_character(code) == "/") parts <- c(parts, "") if (length(parts) == 1) { - if (qty != 1) parts[1] else "" + if (is.finite(qty) & qty == 1) "" else parts[1] } else if (length(parts) == 2) { - if (qty == 1) parts[1] else parts[2] + if (is.finite(qty) & qty == 1) + parts[1] + else + parts[2] } else if (length(parts) == 3) { - if (qty == 0) { + if (is.finite(qty) & qty == 0) { parts[1] - } else if (qty == 1) { + } else if (is.finite(qty) & qty == 1) { parts[2] } else { parts[3] diff --git a/tests/testthat/_snaps/pluralization.md b/tests/testthat/_snaps/pluralization.md index 58ce1eb92..db3c4e3d2 100644 --- a/tests/testthat/_snaps/pluralization.md +++ b/tests/testthat/_snaps/pluralization.md @@ -176,3 +176,96 @@ Output 9 word +# issue 701 + + Code + print(pluralize("{NA} file{?s} expected")) + Output + NA file expected + Code + print(pluralize("{NA_character_} file{?s} expected")) + Output + NA file expected + Code + print(pluralize("{NA_real_} file{?s} expected")) + Output + NA files expected + Code + print(pluralize("{NA_integer_} file{?s} expected")) + Output + NA files expected + Code + print(pluralize("{NaN} file{?s} expected")) + Output + NaN files expected + Code + print(pluralize("{Inf} file{?s} expected")) + Output + Inf files expected + Code + print(pluralize("{-Inf} file{?s} expected")) + Output + -Inf files expected + +--- + + Code + print(pluralize("Found {NA} director{?y/ies}.")) + Output + Found NA directory. + Code + print(pluralize("Found {NA_character_} director{?y/ies}.")) + Output + Found NA directory. + Code + print(pluralize("Found {NA_real_} director{?y/ies}.")) + Output + Found NA directories. + Code + print(pluralize("Found {NA_integer_} director{?y/ies}.")) + Output + Found NA directories. + Code + print(pluralize("Found {NaN} director{?y/ies}.")) + Output + Found NaN directories. + Code + print(pluralize("Found {Inf} director{?y/ies}.")) + Output + Found Inf directories. + Code + print(pluralize("Found {-Inf} director{?y/ies}.")) + Output + Found -Inf directories. + +--- + + Code + print(pluralize("Will remove {?no/the/the} {NA} package{?s}.")) + Output + Will remove the NA package. + Code + print(pluralize("Will remove {?no/the/the} {NA_character_} package{?s}.")) + Output + Will remove the NA package. + Code + print(pluralize("Will remove {?no/the/the} {NA_real_} package{?s}.")) + Output + Will remove the NA packages. + Code + print(pluralize("Will remove {?no/the/the} {NA_integer_} package{?s}.")) + Output + Will remove the NA packages. + Code + print(pluralize("Will remove {?no/the/the} {NaN} package{?s}.")) + Output + Will remove the NaN packages. + Code + print(pluralize("Will remove {?no/the/the} {Inf} package{?s}.")) + Output + Will remove the Inf packages. + Code + print(pluralize("Will remove {?no/the/the} {-Inf} package{?s}.")) + Output + Will remove the -Inf packages. + diff --git a/tests/testthat/test-pluralization.R b/tests/testthat/test-pluralization.R index 46979a2df..eea52b601 100644 --- a/tests/testthat/test-pluralization.R +++ b/tests/testthat/test-pluralization.R @@ -103,3 +103,44 @@ test_that("issue 158", { print(pluralize("{9} word{?A/B/}")) }) }) + +test_that("issue 701", { + expect_snapshot({ + # Should not be pluralized + print(pluralize("{NA} file{?s} expected")) + print(pluralize("{NA_character_} file{?s} expected")) + + # Should be pluralized + print(pluralize("{NA_real_} file{?s} expected")) + print(pluralize("{NA_integer_} file{?s} expected")) + print(pluralize("{NaN} file{?s} expected")) + print(pluralize("{Inf} file{?s} expected")) + print(pluralize("{-Inf} file{?s} expected")) + }) + + expect_snapshot({ + # Should not be pluralized + print(pluralize("Found {NA} director{?y/ies}.")) + print(pluralize("Found {NA_character_} director{?y/ies}.")) + + # Should be pluralized + print(pluralize("Found {NA_real_} director{?y/ies}.")) + print(pluralize("Found {NA_integer_} director{?y/ies}.")) + print(pluralize("Found {NaN} director{?y/ies}.")) + print(pluralize("Found {Inf} director{?y/ies}.")) + print(pluralize("Found {-Inf} director{?y/ies}.")) + }) + + expect_snapshot({ + # Should not be pluralized + print(pluralize("Will remove {?no/the/the} {NA} package{?s}.")) + print(pluralize("Will remove {?no/the/the} {NA_character_} package{?s}.")) + + # Should be pluralized + print(pluralize("Will remove {?no/the/the} {NA_real_} package{?s}.")) + print(pluralize("Will remove {?no/the/the} {NA_integer_} package{?s}.")) + print(pluralize("Will remove {?no/the/the} {NaN} package{?s}.")) + print(pluralize("Will remove {?no/the/the} {Inf} package{?s}.")) + print(pluralize("Will remove {?no/the/the} {-Inf} package{?s}.")) + }) +}) From 31f9c6c2a8a9803770c42053012df4ac891d4bf7 Mon Sep 17 00:00:00 2001 From: Colin Rundel Date: Thu, 15 Aug 2024 11:33:55 -0700 Subject: [PATCH 2/7] Allow last to work with length 2 vectors --- R/glue.R | 11 +++++++++-- tests/testthat/_snaps/collapsing.md | 19 +++++++++++++++++++ tests/testthat/test-collapsing.R | 27 +++++++++++++++++++++++++++ 3 files changed, 55 insertions(+), 2 deletions(-) diff --git a/R/glue.R b/R/glue.R index 3cc96688b..22ba1d069 100644 --- a/R/glue.R +++ b/R/glue.R @@ -130,8 +130,15 @@ collapse_head_notrim <- function(x, trunc, sep, sep2, last, ellipsis) { lnx <- length(x) - if (lnx == 1L) return(x) - if (lnx == 2L) return(paste0(x, collapse = sep2)) + if (lnx == 1L) + return(x) + if (lnx == 2L) { + # Handle the case where last is changed and sep2 is not + if (sep2 == " and " & last != ", and ") + return(paste0(x, collapse = last)) + else + return(paste0(x, collapse = sep2)) + } if (lnx <= trunc) { # no truncation return(paste0( diff --git a/tests/testthat/_snaps/collapsing.md b/tests/testthat/_snaps/collapsing.md index 6d5583385..e9b5421f9 100644 --- a/tests/testthat/_snaps/collapsing.md +++ b/tests/testthat/_snaps/collapsing.md @@ -455,3 +455,22 @@ Output [1] "a, b, c, d, e, f, g, h, i, and j" +# Issue #681 + + Code + v <- cli::cli_vec(c("foo", "bar", "foobar"), style = list(`vec-last` = ", or ")) + cli::cli_text("Must be one of: {v}.") + Message + Must be one of: foo, bar, or foobar. + Code + v <- cli::cli_vec(c("foo", "bar"), style = list(`vec-last` = " or ")) + cli::cli_text("Must be one of: {v}.") + Message + Must be one of: foo or bar. + Code + v <- cli::cli_vec(c("foo", "bar"), style = list(`vec-last` = " or ", + `vec-sep2` = " xor ")) + cli::cli_text("Must be one of: {v}.") + Message + Must be one of: foo xor bar. + diff --git a/tests/testthat/test-collapsing.R b/tests/testthat/test-collapsing.R index 4923dcc3e..2a567cc5c 100644 --- a/tests/testthat/test-collapsing.R +++ b/tests/testthat/test-collapsing.R @@ -197,3 +197,30 @@ test_that("ansi_collapse uses `sep2` for length-two inputs", { expect_equal(ansi_collapse(1:2, trunc = 2, style = "head"), "1 and 2") }) + + +test_that("Issue #681", { + expect_equal(ansi_collapse(1:2, last = " or "), "1 or 2") + expect_equal(ansi_collapse(1:2, sep2 = " and ", last = " or "), "1 or 2") + expect_equal(ansi_collapse(1:2, sep2 = " xor ", last = " or "), "1 xor 2") + + expect_snapshot({ + v <- cli::cli_vec( + c("foo", "bar", "foobar"), + style = list("vec-last" = ", or ") + ) + cli::cli_text("Must be one of: {v}.") + + v <- cli::cli_vec( + c("foo", "bar"), + style = list("vec-last" = " or ") + ) + cli::cli_text("Must be one of: {v}.") + + v <- cli::cli_vec( + c("foo", "bar"), + style = list("vec-last" = " or ", "vec-sep2" = " xor ") + ) + cli::cli_text("Must be one of: {v}.") + }) +}) From b53d79c1b50228a4cbed7e46f32a5e23129e3161 Mon Sep 17 00:00:00 2001 From: Colin Rundel Date: Thu, 15 Aug 2024 14:40:43 -0400 Subject: [PATCH 3/7] Update tests/testthat/test-pluralization.R MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Kirill Müller --- tests/testthat/test-pluralization.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/testthat/test-pluralization.R b/tests/testthat/test-pluralization.R index eea52b601..994e85859 100644 --- a/tests/testthat/test-pluralization.R +++ b/tests/testthat/test-pluralization.R @@ -104,7 +104,7 @@ test_that("issue 158", { }) }) -test_that("issue 701", { +test_that("Edge cases for pluralize() (#701)", { expect_snapshot({ # Should not be pluralized print(pluralize("{NA} file{?s} expected")) From 53b1c8a2f7b4305ca9172e0ee72ca69b6fb41e80 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A1bor=20Cs=C3=A1rdi?= Date: Wed, 28 Aug 2024 12:22:06 +0200 Subject: [PATCH 4/7] Undo the ansi_collapse() fix Will have a different workaround. --- R/glue.R | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/R/glue.R b/R/glue.R index 22ba1d069..3cc96688b 100644 --- a/R/glue.R +++ b/R/glue.R @@ -130,15 +130,8 @@ collapse_head_notrim <- function(x, trunc, sep, sep2, last, ellipsis) { lnx <- length(x) - if (lnx == 1L) - return(x) - if (lnx == 2L) { - # Handle the case where last is changed and sep2 is not - if (sep2 == " and " & last != ", and ") - return(paste0(x, collapse = last)) - else - return(paste0(x, collapse = sep2)) - } + if (lnx == 1L) return(x) + if (lnx == 2L) return(paste0(x, collapse = sep2)) if (lnx <= trunc) { # no truncation return(paste0( From a8698f2ec6d90c753e9ca84808b27e02b98b4a4c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A1bor=20Cs=C3=A1rdi?= Date: Wed, 28 Aug 2024 12:22:52 +0200 Subject: [PATCH 5/7] Use vec-last for length-2 vecs if no vec-sep2 Another fix for #681. --- R/glue.R | 5 +++-- R/inline.R | 4 ++-- tests/testthat/test-collapsing.R | 8 ++++++-- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/R/glue.R b/R/glue.R index 3cc96688b..76f3914b6 100644 --- a/R/glue.R +++ b/R/glue.R @@ -79,7 +79,8 @@ drop_null <- function(x) { #' to collapse. #' @param sep Separator. A character string. #' @param sep2 Separator for the special case that `x` contains only two -#' elements. A character string. +#' elements. A character string. Defaults to the value of `last` without the +#' serial comma. #' @param last Last separator, if there is no truncation. E.g. use #' `", and "` for the [serial #' comma](https://en.wikipedia.org/wiki/Serial_comma). A character string. @@ -112,7 +113,7 @@ drop_null <- function(x) { #' # head style #' ansi_collapse(letters, trunc = 5, style = "head") -ansi_collapse <- function(x, sep = ", ", sep2 = " and ", last = ", and ", +ansi_collapse <- function(x, sep = ", ", sep2 = sub("^,", "", last), last = ", and ", trunc = Inf, width = Inf, ellipsis = symbol$ellipsis, style = c("both-ends", "head")) { diff --git a/R/inline.R b/R/inline.R index 3152bfb72..2a28eb2d3 100644 --- a/R/inline.R +++ b/R/inline.R @@ -43,9 +43,9 @@ inline_generic <- function(app, x, style) { } inline_collapse <- function(x, style = list()) { - sep <- style[["vec-sep"]] %||% style[["vec_sep"]] %||% ", " - sep2 <- style[["vec-sep2"]] %||% style[["vec_sep2"]] %||% " and " last <- style[["vec-last"]] %||% style[["vec_last"]] %||% ", and " + sep <- style[["vec-sep"]] %||% style[["vec_sep"]] %||% ", " + sep2 <- style[["vec-sep2"]] %||% style[["vec_sep2"]] %||% sub("^,", "", last) trunc <- style[["vec-trunc"]] %||% style[["vec_trunc"]] %||% 20L col_style <- style[["vec-trunc-style"]] %||% "both-ends" diff --git a/tests/testthat/test-collapsing.R b/tests/testthat/test-collapsing.R index 2a567cc5c..67ee579e7 100644 --- a/tests/testthat/test-collapsing.R +++ b/tests/testthat/test-collapsing.R @@ -200,9 +200,13 @@ test_that("ansi_collapse uses `sep2` for length-two inputs", { test_that("Issue #681", { - expect_equal(ansi_collapse(1:2, last = " or "), "1 or 2") - expect_equal(ansi_collapse(1:2, sep2 = " and ", last = " or "), "1 or 2") + # sep2 takes precedence + expect_equal(ansi_collapse(1:2, sep2 = " and ", last = " or "), "1 and 2") expect_equal(ansi_collapse(1:2, sep2 = " xor ", last = " or "), "1 xor 2") + # default for sep2 is last without the Oxford comma + expect_equal(ansi_collapse(1:3, last = ", or "), "1, 2, or 3") + expect_equal(ansi_collapse(1:2, last = ", or "), "1 or 2") + expect_equal(ansi_collapse(1:2, last = " or "), "1 or 2") expect_snapshot({ v <- cli::cli_vec( From 13ff424cec716cd12e703f01c5b3eef501873a6f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A1bor=20Cs=C3=A1rdi?= Date: Wed, 28 Aug 2024 12:26:48 +0200 Subject: [PATCH 6/7] Update manual --- DESCRIPTION | 2 +- man/ansi_align.Rd | 2 +- man/ansi_collapse.Rd | 5 +++-- man/ansi_columns.Rd | 2 +- man/ansi_nchar.Rd | 2 +- man/ansi_strsplit.Rd | 2 +- man/ansi_strtrim.Rd | 2 +- man/ansi_strwrap.Rd | 2 +- man/ansi_toupper.Rd | 6 +++--- man/ansi_trimws.Rd | 2 +- man/cli_abort.Rd | 4 ++-- man/cli_alert.Rd | 4 ++-- man/cli_blockquote.Rd | 4 ++-- man/cli_bullets.Rd | 2 +- man/cli_bullets_raw.Rd | 2 +- man/cli_dl.Rd | 4 ++-- man/cli_h1.Rd | 4 ++-- man/cli_li.Rd | 4 ++-- man/cli_ol.Rd | 4 ++-- man/cli_process_start.Rd | 8 ++++---- man/cli_progress_along.Rd | 4 ++-- man/cli_progress_bar.Rd | 4 ++-- man/cli_progress_message.Rd | 4 ++-- man/cli_progress_output.Rd | 4 ++-- man/cli_progress_step.Rd | 4 ++-- man/cli_rule.Rd | 4 ++-- man/cli_status.Rd | 2 +- man/cli_status_clear.Rd | 4 ++-- man/cli_status_update.Rd | 6 +++--- man/cli_text.Rd | 4 ++-- man/cli_ul.Rd | 4 ++-- man/format_error.Rd | 4 ++-- man/format_inline.Rd | 4 ++-- man/inline-markup.Rd | 3 ++- man/pluralization-helpers.Rd | 14 ++++++++++++++ 35 files changed, 76 insertions(+), 60 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 4e5c0e03d..c9a722517 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -59,4 +59,4 @@ Config/Needs/website: vctrs Config/testthat/edition: 3 Encoding: UTF-8 -RoxygenNote: 7.2.3 +RoxygenNote: 7.3.2 diff --git a/man/ansi_align.Rd b/man/ansi_align.Rd index e9886d11a..17a716875 100644 --- a/man/ansi_align.Rd +++ b/man/ansi_align.Rd @@ -87,8 +87,8 @@ Other ANSI string operations: \code{\link{ansi_strsplit}()}, \code{\link{ansi_strtrim}()}, \code{\link{ansi_strwrap}()}, -\code{\link{ansi_substring}()}, \code{\link{ansi_substr}()}, +\code{\link{ansi_substring}()}, \code{\link{ansi_toupper}()}, \code{\link{ansi_trimws}()} } diff --git a/man/ansi_collapse.Rd b/man/ansi_collapse.Rd index 4e90d0648..4fb5a1fd3 100644 --- a/man/ansi_collapse.Rd +++ b/man/ansi_collapse.Rd @@ -7,7 +7,7 @@ ansi_collapse( x, sep = ", ", - sep2 = " and ", + sep2 = sub("^,", "", last), last = ", and ", trunc = Inf, width = Inf, @@ -22,7 +22,8 @@ to collapse.} \item{sep}{Separator. A character string.} \item{sep2}{Separator for the special case that \code{x} contains only two -elements. A character string.} +elements. A character string. Defaults to the value of \code{last} without the +serial comma.} \item{last}{Last separator, if there is no truncation. E.g. use \code{", and "} for the \href{https://en.wikipedia.org/wiki/Serial_comma}{serial comma}. A character string.} diff --git a/man/ansi_columns.Rd b/man/ansi_columns.Rd index add06afd0..dd9b1235c 100644 --- a/man/ansi_columns.Rd +++ b/man/ansi_columns.Rd @@ -72,8 +72,8 @@ Other ANSI string operations: \code{\link{ansi_strsplit}()}, \code{\link{ansi_strtrim}()}, \code{\link{ansi_strwrap}()}, -\code{\link{ansi_substring}()}, \code{\link{ansi_substr}()}, +\code{\link{ansi_substring}()}, \code{\link{ansi_toupper}()}, \code{\link{ansi_trimws}()} } diff --git a/man/ansi_nchar.Rd b/man/ansi_nchar.Rd index edf3219ae..23a32d868 100644 --- a/man/ansi_nchar.Rd +++ b/man/ansi_nchar.Rd @@ -40,8 +40,8 @@ Other ANSI string operations: \code{\link{ansi_strsplit}()}, \code{\link{ansi_strtrim}()}, \code{\link{ansi_strwrap}()}, -\code{\link{ansi_substring}()}, \code{\link{ansi_substr}()}, +\code{\link{ansi_substring}()}, \code{\link{ansi_toupper}()}, \code{\link{ansi_trimws}()} } diff --git a/man/ansi_strsplit.Rd b/man/ansi_strsplit.Rd index 020477f41..125466a9c 100644 --- a/man/ansi_strsplit.Rd +++ b/man/ansi_strsplit.Rd @@ -51,8 +51,8 @@ Other ANSI string operations: \code{\link{ansi_nchar}()}, \code{\link{ansi_strtrim}()}, \code{\link{ansi_strwrap}()}, -\code{\link{ansi_substring}()}, \code{\link{ansi_substr}()}, +\code{\link{ansi_substring}()}, \code{\link{ansi_toupper}()}, \code{\link{ansi_trimws}()} } diff --git a/man/ansi_strtrim.Rd b/man/ansi_strtrim.Rd index 9a1818732..c530c1f0b 100644 --- a/man/ansi_strtrim.Rd +++ b/man/ansi_strtrim.Rd @@ -34,8 +34,8 @@ Other ANSI string operations: \code{\link{ansi_nchar}()}, \code{\link{ansi_strsplit}()}, \code{\link{ansi_strwrap}()}, -\code{\link{ansi_substring}()}, \code{\link{ansi_substr}()}, +\code{\link{ansi_substring}()}, \code{\link{ansi_toupper}()}, \code{\link{ansi_trimws}()} } diff --git a/man/ansi_strwrap.Rd b/man/ansi_strwrap.Rd index 189de95dc..41d597d4b 100644 --- a/man/ansi_strwrap.Rd +++ b/man/ansi_strwrap.Rd @@ -50,8 +50,8 @@ Other ANSI string operations: \code{\link{ansi_nchar}()}, \code{\link{ansi_strsplit}()}, \code{\link{ansi_strtrim}()}, -\code{\link{ansi_substring}()}, \code{\link{ansi_substr}()}, +\code{\link{ansi_substring}()}, \code{\link{ansi_toupper}()}, \code{\link{ansi_trimws}()} } diff --git a/man/ansi_toupper.Rd b/man/ansi_toupper.Rd index b8ab6b846..66bdf3017 100644 --- a/man/ansi_toupper.Rd +++ b/man/ansi_toupper.Rd @@ -47,8 +47,8 @@ Other ANSI string operations: \code{\link{ansi_strsplit}()}, \code{\link{ansi_strtrim}()}, \code{\link{ansi_strwrap}()}, -\code{\link{ansi_substring}()}, \code{\link{ansi_substr}()}, +\code{\link{ansi_substring}()}, \code{\link{ansi_trimws}()} Other ANSI string operations: @@ -58,8 +58,8 @@ Other ANSI string operations: \code{\link{ansi_strsplit}()}, \code{\link{ansi_strtrim}()}, \code{\link{ansi_strwrap}()}, -\code{\link{ansi_substring}()}, \code{\link{ansi_substr}()}, +\code{\link{ansi_substring}()}, \code{\link{ansi_trimws}()} Other ANSI string operations: @@ -69,8 +69,8 @@ Other ANSI string operations: \code{\link{ansi_strsplit}()}, \code{\link{ansi_strtrim}()}, \code{\link{ansi_strwrap}()}, -\code{\link{ansi_substring}()}, \code{\link{ansi_substr}()}, +\code{\link{ansi_substring}()}, \code{\link{ansi_trimws}()} } \concept{ANSI string operations} diff --git a/man/ansi_trimws.Rd b/man/ansi_trimws.Rd index 5ca314b8b..2da8d219c 100644 --- a/man/ansi_trimws.Rd +++ b/man/ansi_trimws.Rd @@ -32,8 +32,8 @@ Other ANSI string operations: \code{\link{ansi_strsplit}()}, \code{\link{ansi_strtrim}()}, \code{\link{ansi_strwrap}()}, -\code{\link{ansi_substring}()}, \code{\link{ansi_substr}()}, +\code{\link{ansi_substring}()}, \code{\link{ansi_toupper}()} } \concept{ANSI string operations} diff --git a/man/cli_abort.Rd b/man/cli_abort.Rd index 25e5e29c1..c04859a61 100644 --- a/man/cli_abort.Rd +++ b/man/cli_abort.Rd @@ -89,8 +89,8 @@ These functions support \link[=inline-markup]{inline markup}. Other functions supporting inline markup: \code{\link{cli_alert}()}, \code{\link{cli_blockquote}()}, -\code{\link{cli_bullets_raw}()}, \code{\link{cli_bullets}()}, +\code{\link{cli_bullets_raw}()}, \code{\link{cli_dl}()}, \code{\link{cli_h1}()}, \code{\link{cli_li}()}, @@ -102,8 +102,8 @@ Other functions supporting inline markup: \code{\link{cli_progress_output}()}, \code{\link{cli_progress_step}()}, \code{\link{cli_rule}}, -\code{\link{cli_status_update}()}, \code{\link{cli_status}()}, +\code{\link{cli_status_update}()}, \code{\link{cli_text}()}, \code{\link{cli_ul}()}, \code{\link{format_error}()}, diff --git a/man/cli_alert.Rd b/man/cli_alert.Rd index f1ecd410b..736cd20fa 100644 --- a/man/cli_alert.Rd +++ b/man/cli_alert.Rd @@ -129,8 +129,8 @@ These functions supports \link[=inline-markup]{inline markup}. Other functions supporting inline markup: \code{\link{cli_abort}()}, \code{\link{cli_blockquote}()}, -\code{\link{cli_bullets_raw}()}, \code{\link{cli_bullets}()}, +\code{\link{cli_bullets_raw}()}, \code{\link{cli_dl}()}, \code{\link{cli_h1}()}, \code{\link{cli_li}()}, @@ -142,8 +142,8 @@ Other functions supporting inline markup: \code{\link{cli_progress_output}()}, \code{\link{cli_progress_step}()}, \code{\link{cli_rule}}, -\code{\link{cli_status_update}()}, \code{\link{cli_status}()}, +\code{\link{cli_status_update}()}, \code{\link{cli_text}()}, \code{\link{cli_ul}()}, \code{\link{format_error}()}, diff --git a/man/cli_blockquote.Rd b/man/cli_blockquote.Rd index 37b13074d..a5b520ac4 100644 --- a/man/cli_blockquote.Rd +++ b/man/cli_blockquote.Rd @@ -55,8 +55,8 @@ This function supports \link[=inline-markup]{inline markup}. Other functions supporting inline markup: \code{\link{cli_abort}()}, \code{\link{cli_alert}()}, -\code{\link{cli_bullets_raw}()}, \code{\link{cli_bullets}()}, +\code{\link{cli_bullets_raw}()}, \code{\link{cli_dl}()}, \code{\link{cli_h1}()}, \code{\link{cli_li}()}, @@ -68,8 +68,8 @@ Other functions supporting inline markup: \code{\link{cli_progress_output}()}, \code{\link{cli_progress_step}()}, \code{\link{cli_rule}}, -\code{\link{cli_status_update}()}, \code{\link{cli_status}()}, +\code{\link{cli_status_update}()}, \code{\link{cli_text}()}, \code{\link{cli_ul}()}, \code{\link{format_error}()}, diff --git a/man/cli_bullets.Rd b/man/cli_bullets.Rd index 7793fc86c..5027f9a18 100644 --- a/man/cli_bullets.Rd +++ b/man/cli_bullets.Rd @@ -86,8 +86,8 @@ Other functions supporting inline markup: \code{\link{cli_progress_output}()}, \code{\link{cli_progress_step}()}, \code{\link{cli_rule}}, -\code{\link{cli_status_update}()}, \code{\link{cli_status}()}, +\code{\link{cli_status_update}()}, \code{\link{cli_text}()}, \code{\link{cli_ul}()}, \code{\link{format_error}()}, diff --git a/man/cli_bullets_raw.Rd b/man/cli_bullets_raw.Rd index 3b3dfba45..d850fef1e 100644 --- a/man/cli_bullets_raw.Rd +++ b/man/cli_bullets_raw.Rd @@ -45,8 +45,8 @@ Other functions supporting inline markup: \code{\link{cli_progress_output}()}, \code{\link{cli_progress_step}()}, \code{\link{cli_rule}}, -\code{\link{cli_status_update}()}, \code{\link{cli_status}()}, +\code{\link{cli_status_update}()}, \code{\link{cli_text}()}, \code{\link{cli_ul}()}, \code{\link{format_error}()}, diff --git a/man/cli_dl.Rd b/man/cli_dl.Rd index 7b5866eea..2c39d51b1 100644 --- a/man/cli_dl.Rd +++ b/man/cli_dl.Rd @@ -84,8 +84,8 @@ Other functions supporting inline markup: \code{\link{cli_abort}()}, \code{\link{cli_alert}()}, \code{\link{cli_blockquote}()}, -\code{\link{cli_bullets_raw}()}, \code{\link{cli_bullets}()}, +\code{\link{cli_bullets_raw}()}, \code{\link{cli_h1}()}, \code{\link{cli_li}()}, \code{\link{cli_ol}()}, @@ -96,8 +96,8 @@ Other functions supporting inline markup: \code{\link{cli_progress_output}()}, \code{\link{cli_progress_step}()}, \code{\link{cli_rule}}, -\code{\link{cli_status_update}()}, \code{\link{cli_status}()}, +\code{\link{cli_status_update}()}, \code{\link{cli_text}()}, \code{\link{cli_ul}()}, \code{\link{format_error}()}, diff --git a/man/cli_h1.Rd b/man/cli_h1.Rd index a5b3c1e0f..e55bb61fd 100644 --- a/man/cli_h1.Rd +++ b/man/cli_h1.Rd @@ -49,8 +49,8 @@ Other functions supporting inline markup: \code{\link{cli_abort}()}, \code{\link{cli_alert}()}, \code{\link{cli_blockquote}()}, -\code{\link{cli_bullets_raw}()}, \code{\link{cli_bullets}()}, +\code{\link{cli_bullets_raw}()}, \code{\link{cli_dl}()}, \code{\link{cli_li}()}, \code{\link{cli_ol}()}, @@ -61,8 +61,8 @@ Other functions supporting inline markup: \code{\link{cli_progress_output}()}, \code{\link{cli_progress_step}()}, \code{\link{cli_rule}}, -\code{\link{cli_status_update}()}, \code{\link{cli_status}()}, +\code{\link{cli_status_update}()}, \code{\link{cli_text}()}, \code{\link{cli_ul}()}, \code{\link{format_error}()}, diff --git a/man/cli_li.Rd b/man/cli_li.Rd index cbb176164..cd6dd3ed0 100644 --- a/man/cli_li.Rd +++ b/man/cli_li.Rd @@ -68,8 +68,8 @@ Other functions supporting inline markup: \code{\link{cli_abort}()}, \code{\link{cli_alert}()}, \code{\link{cli_blockquote}()}, -\code{\link{cli_bullets_raw}()}, \code{\link{cli_bullets}()}, +\code{\link{cli_bullets_raw}()}, \code{\link{cli_dl}()}, \code{\link{cli_h1}()}, \code{\link{cli_ol}()}, @@ -80,8 +80,8 @@ Other functions supporting inline markup: \code{\link{cli_progress_output}()}, \code{\link{cli_progress_step}()}, \code{\link{cli_rule}}, -\code{\link{cli_status_update}()}, \code{\link{cli_status}()}, +\code{\link{cli_status_update}()}, \code{\link{cli_text}()}, \code{\link{cli_ul}()}, \code{\link{format_error}()}, diff --git a/man/cli_ol.Rd b/man/cli_ol.Rd index fe1531ebb..677988697 100644 --- a/man/cli_ol.Rd +++ b/man/cli_ol.Rd @@ -108,8 +108,8 @@ Other functions supporting inline markup: \code{\link{cli_abort}()}, \code{\link{cli_alert}()}, \code{\link{cli_blockquote}()}, -\code{\link{cli_bullets_raw}()}, \code{\link{cli_bullets}()}, +\code{\link{cli_bullets_raw}()}, \code{\link{cli_dl}()}, \code{\link{cli_h1}()}, \code{\link{cli_li}()}, @@ -120,8 +120,8 @@ Other functions supporting inline markup: \code{\link{cli_progress_output}()}, \code{\link{cli_progress_step}()}, \code{\link{cli_rule}}, -\code{\link{cli_status_update}()}, \code{\link{cli_status}()}, +\code{\link{cli_status_update}()}, \code{\link{cli_text}()}, \code{\link{cli_ul}()}, \code{\link{format_error}()}, diff --git a/man/cli_process_start.Rd b/man/cli_process_start.Rd index 631ebee68..d6238b0ef 100644 --- a/man/cli_process_start.Rd +++ b/man/cli_process_start.Rd @@ -118,16 +118,16 @@ The \code{\link[=cli_progress_message]{cli_progress_message()}} and \code{\link[ functions, for a superior API. Other status bar: +\code{\link{cli_status}()}, \code{\link{cli_status_clear}()}, -\code{\link{cli_status_update}()}, -\code{\link{cli_status}()} +\code{\link{cli_status_update}()} Other functions supporting inline markup: \code{\link{cli_abort}()}, \code{\link{cli_alert}()}, \code{\link{cli_blockquote}()}, -\code{\link{cli_bullets_raw}()}, \code{\link{cli_bullets}()}, +\code{\link{cli_bullets_raw}()}, \code{\link{cli_dl}()}, \code{\link{cli_h1}()}, \code{\link{cli_li}()}, @@ -138,8 +138,8 @@ Other functions supporting inline markup: \code{\link{cli_progress_output}()}, \code{\link{cli_progress_step}()}, \code{\link{cli_rule}}, -\code{\link{cli_status_update}()}, \code{\link{cli_status}()}, +\code{\link{cli_status_update}()}, \code{\link{cli_text}()}, \code{\link{cli_ul}()}, \code{\link{format_error}()}, diff --git a/man/cli_progress_along.Rd b/man/cli_progress_along.Rd index 88c900ae9..3b34b01dc 100644 --- a/man/cli_progress_along.Rd +++ b/man/cli_progress_along.Rd @@ -121,8 +121,8 @@ Other functions supporting inline markup: \code{\link{cli_abort}()}, \code{\link{cli_alert}()}, \code{\link{cli_blockquote}()}, -\code{\link{cli_bullets_raw}()}, \code{\link{cli_bullets}()}, +\code{\link{cli_bullets_raw}()}, \code{\link{cli_dl}()}, \code{\link{cli_h1}()}, \code{\link{cli_li}()}, @@ -133,8 +133,8 @@ Other functions supporting inline markup: \code{\link{cli_progress_output}()}, \code{\link{cli_progress_step}()}, \code{\link{cli_rule}}, -\code{\link{cli_status_update}()}, \code{\link{cli_status}()}, +\code{\link{cli_status_update}()}, \code{\link{cli_text}()}, \code{\link{cli_ul}()}, \code{\link{format_error}()}, diff --git a/man/cli_progress_bar.Rd b/man/cli_progress_bar.Rd index 8bf2ba299..bb9bfeb86 100644 --- a/man/cli_progress_bar.Rd +++ b/man/cli_progress_bar.Rd @@ -380,8 +380,8 @@ Other functions supporting inline markup: \code{\link{cli_abort}()}, \code{\link{cli_alert}()}, \code{\link{cli_blockquote}()}, -\code{\link{cli_bullets_raw}()}, \code{\link{cli_bullets}()}, +\code{\link{cli_bullets_raw}()}, \code{\link{cli_dl}()}, \code{\link{cli_h1}()}, \code{\link{cli_li}()}, @@ -392,8 +392,8 @@ Other functions supporting inline markup: \code{\link{cli_progress_output}()}, \code{\link{cli_progress_step}()}, \code{\link{cli_rule}}, -\code{\link{cli_status_update}()}, \code{\link{cli_status}()}, +\code{\link{cli_status_update}()}, \code{\link{cli_text}()}, \code{\link{cli_ul}()}, \code{\link{format_error}()}, diff --git a/man/cli_progress_message.Rd b/man/cli_progress_message.Rd index 9aa3fb679..023769095 100644 --- a/man/cli_progress_message.Rd +++ b/man/cli_progress_message.Rd @@ -79,8 +79,8 @@ Other functions supporting inline markup: \code{\link{cli_abort}()}, \code{\link{cli_alert}()}, \code{\link{cli_blockquote}()}, -\code{\link{cli_bullets_raw}()}, \code{\link{cli_bullets}()}, +\code{\link{cli_bullets_raw}()}, \code{\link{cli_dl}()}, \code{\link{cli_h1}()}, \code{\link{cli_li}()}, @@ -91,8 +91,8 @@ Other functions supporting inline markup: \code{\link{cli_progress_output}()}, \code{\link{cli_progress_step}()}, \code{\link{cli_rule}}, -\code{\link{cli_status_update}()}, \code{\link{cli_status}()}, +\code{\link{cli_status_update}()}, \code{\link{cli_text}()}, \code{\link{cli_ul}()}, \code{\link{format_error}()}, diff --git a/man/cli_progress_output.Rd b/man/cli_progress_output.Rd index ce43e33d9..6cbe4a64b 100644 --- a/man/cli_progress_output.Rd +++ b/man/cli_progress_output.Rd @@ -60,8 +60,8 @@ Other functions supporting inline markup: \code{\link{cli_abort}()}, \code{\link{cli_alert}()}, \code{\link{cli_blockquote}()}, -\code{\link{cli_bullets_raw}()}, \code{\link{cli_bullets}()}, +\code{\link{cli_bullets_raw}()}, \code{\link{cli_dl}()}, \code{\link{cli_h1}()}, \code{\link{cli_li}()}, @@ -72,8 +72,8 @@ Other functions supporting inline markup: \code{\link{cli_progress_message}()}, \code{\link{cli_progress_step}()}, \code{\link{cli_rule}}, -\code{\link{cli_status_update}()}, \code{\link{cli_status}()}, +\code{\link{cli_status_update}()}, \code{\link{cli_text}()}, \code{\link{cli_ul}()}, \code{\link{format_error}()}, diff --git a/man/cli_progress_step.Rd b/man/cli_progress_step.Rd index 37ef67943..6f12015a6 100644 --- a/man/cli_progress_step.Rd +++ b/man/cli_progress_step.Rd @@ -159,8 +159,8 @@ Other functions supporting inline markup: \code{\link{cli_abort}()}, \code{\link{cli_alert}()}, \code{\link{cli_blockquote}()}, -\code{\link{cli_bullets_raw}()}, \code{\link{cli_bullets}()}, +\code{\link{cli_bullets_raw}()}, \code{\link{cli_dl}()}, \code{\link{cli_h1}()}, \code{\link{cli_li}()}, @@ -171,8 +171,8 @@ Other functions supporting inline markup: \code{\link{cli_progress_message}()}, \code{\link{cli_progress_output}()}, \code{\link{cli_rule}}, -\code{\link{cli_status_update}()}, \code{\link{cli_status}()}, +\code{\link{cli_status_update}()}, \code{\link{cli_text}()}, \code{\link{cli_ul}()}, \code{\link{format_error}()}, diff --git a/man/cli_rule.Rd b/man/cli_rule.Rd index c18e4db4e..c42214c87 100644 --- a/man/cli_rule.Rd +++ b/man/cli_rule.Rd @@ -75,8 +75,8 @@ Other functions supporting inline markup: \code{\link{cli_abort}()}, \code{\link{cli_alert}()}, \code{\link{cli_blockquote}()}, -\code{\link{cli_bullets_raw}()}, \code{\link{cli_bullets}()}, +\code{\link{cli_bullets_raw}()}, \code{\link{cli_dl}()}, \code{\link{cli_h1}()}, \code{\link{cli_li}()}, @@ -87,8 +87,8 @@ Other functions supporting inline markup: \code{\link{cli_progress_message}()}, \code{\link{cli_progress_output}()}, \code{\link{cli_progress_step}()}, -\code{\link{cli_status_update}()}, \code{\link{cli_status}()}, +\code{\link{cli_status_update}()}, \code{\link{cli_text}()}, \code{\link{cli_ul}()}, \code{\link{format_error}()}, diff --git a/man/cli_status.Rd b/man/cli_status.Rd index 070589d3d..dbb6fa5ef 100644 --- a/man/cli_status.Rd +++ b/man/cli_status.Rd @@ -80,8 +80,8 @@ Other functions supporting inline markup: \code{\link{cli_abort}()}, \code{\link{cli_alert}()}, \code{\link{cli_blockquote}()}, -\code{\link{cli_bullets_raw}()}, \code{\link{cli_bullets}()}, +\code{\link{cli_bullets_raw}()}, \code{\link{cli_dl}()}, \code{\link{cli_h1}()}, \code{\link{cli_li}()}, diff --git a/man/cli_status_clear.Rd b/man/cli_status_clear.Rd index 6f00e8404..875ae0f89 100644 --- a/man/cli_status_clear.Rd +++ b/man/cli_status_clear.Rd @@ -45,7 +45,7 @@ functions, for a superior API. Other status bar: \code{\link{cli_process_start}()}, -\code{\link{cli_status_update}()}, -\code{\link{cli_status}()} +\code{\link{cli_status}()}, +\code{\link{cli_status_update}()} } \concept{status bar} diff --git a/man/cli_status_update.Rd b/man/cli_status_update.Rd index 04f5d17dc..9045f2f9b 100644 --- a/man/cli_status_update.Rd +++ b/man/cli_status_update.Rd @@ -45,15 +45,15 @@ functions, for a superior API. Other status bar: \code{\link{cli_process_start}()}, -\code{\link{cli_status_clear}()}, -\code{\link{cli_status}()} +\code{\link{cli_status}()}, +\code{\link{cli_status_clear}()} Other functions supporting inline markup: \code{\link{cli_abort}()}, \code{\link{cli_alert}()}, \code{\link{cli_blockquote}()}, -\code{\link{cli_bullets_raw}()}, \code{\link{cli_bullets}()}, +\code{\link{cli_bullets_raw}()}, \code{\link{cli_dl}()}, \code{\link{cli_h1}()}, \code{\link{cli_li}()}, diff --git a/man/cli_text.Rd b/man/cli_text.Rd index 4b1758a7f..c3027099d 100644 --- a/man/cli_text.Rd +++ b/man/cli_text.Rd @@ -133,8 +133,8 @@ Other functions supporting inline markup: \code{\link{cli_abort}()}, \code{\link{cli_alert}()}, \code{\link{cli_blockquote}()}, -\code{\link{cli_bullets_raw}()}, \code{\link{cli_bullets}()}, +\code{\link{cli_bullets_raw}()}, \code{\link{cli_dl}()}, \code{\link{cli_h1}()}, \code{\link{cli_li}()}, @@ -146,8 +146,8 @@ Other functions supporting inline markup: \code{\link{cli_progress_output}()}, \code{\link{cli_progress_step}()}, \code{\link{cli_rule}}, -\code{\link{cli_status_update}()}, \code{\link{cli_status}()}, +\code{\link{cli_status_update}()}, \code{\link{cli_ul}()}, \code{\link{format_error}()}, \code{\link{format_inline}()} diff --git a/man/cli_ul.Rd b/man/cli_ul.Rd index a5f13b3ff..b9e18a7e9 100644 --- a/man/cli_ul.Rd +++ b/man/cli_ul.Rd @@ -83,8 +83,8 @@ Other functions supporting inline markup: \code{\link{cli_abort}()}, \code{\link{cli_alert}()}, \code{\link{cli_blockquote}()}, -\code{\link{cli_bullets_raw}()}, \code{\link{cli_bullets}()}, +\code{\link{cli_bullets_raw}()}, \code{\link{cli_dl}()}, \code{\link{cli_h1}()}, \code{\link{cli_li}()}, @@ -96,8 +96,8 @@ Other functions supporting inline markup: \code{\link{cli_progress_output}()}, \code{\link{cli_progress_step}()}, \code{\link{cli_rule}}, -\code{\link{cli_status_update}()}, \code{\link{cli_status}()}, +\code{\link{cli_status_update}()}, \code{\link{cli_text}()}, \code{\link{format_error}()}, \code{\link{format_inline}()} diff --git a/man/format_error.Rd b/man/format_error.Rd index b09790fba..b59585624 100644 --- a/man/format_error.Rd +++ b/man/format_error.Rd @@ -59,8 +59,8 @@ Other functions supporting inline markup: \code{\link{cli_abort}()}, \code{\link{cli_alert}()}, \code{\link{cli_blockquote}()}, -\code{\link{cli_bullets_raw}()}, \code{\link{cli_bullets}()}, +\code{\link{cli_bullets_raw}()}, \code{\link{cli_dl}()}, \code{\link{cli_h1}()}, \code{\link{cli_li}()}, @@ -72,8 +72,8 @@ Other functions supporting inline markup: \code{\link{cli_progress_output}()}, \code{\link{cli_progress_step}()}, \code{\link{cli_rule}}, -\code{\link{cli_status_update}()}, \code{\link{cli_status}()}, +\code{\link{cli_status_update}()}, \code{\link{cli_text}()}, \code{\link{cli_ul}()}, \code{\link{format_inline}()} diff --git a/man/format_inline.Rd b/man/format_inline.Rd index 673f82d1d..9be129ce1 100644 --- a/man/format_inline.Rd +++ b/man/format_inline.Rd @@ -42,8 +42,8 @@ Other functions supporting inline markup: \code{\link{cli_abort}()}, \code{\link{cli_alert}()}, \code{\link{cli_blockquote}()}, -\code{\link{cli_bullets_raw}()}, \code{\link{cli_bullets}()}, +\code{\link{cli_bullets_raw}()}, \code{\link{cli_dl}()}, \code{\link{cli_h1}()}, \code{\link{cli_li}()}, @@ -55,8 +55,8 @@ Other functions supporting inline markup: \code{\link{cli_progress_output}()}, \code{\link{cli_progress_step}()}, \code{\link{cli_rule}}, -\code{\link{cli_status_update}()}, \code{\link{cli_status}()}, +\code{\link{cli_status_update}()}, \code{\link{cli_text}()}, \code{\link{cli_ul}()}, \code{\link{format_error}()} diff --git a/man/inline-markup.Rd b/man/inline-markup.Rd index c281c451d..28f3d5c7b 100644 --- a/man/inline-markup.Rd +++ b/man/inline-markup.Rd @@ -99,7 +99,8 @@ collapsed vectors (see below) from "and" to "or". \item \code{run} is an R expression, that is potentially clickable if the terminal supports ANSI hyperlinks to runnable code (e.g. RStudio). It supports link text. See \link{links} for more information about cli hyperlinks. -\item \code{str} for a double quoted string escaped by \code{\link[base:encodeString]{base::encodeString()}}.#' * \code{strong} for strong importance. +\item \code{str} for a double quoted string escaped by \code{\link[base:encodeString]{base::encodeString()}}. +\item \code{strong} for strong importance. \item \code{topic} is a help page of a \emph{topic}. If the terminal supports ANSI hyperlinks to help pages (e.g. RStudio), then cli creates a clickable link. It supports link text. diff --git a/man/pluralization-helpers.Rd b/man/pluralization-helpers.Rd index f9700edd5..bcb46dfdd 100644 --- a/man/pluralization-helpers.Rd +++ b/man/pluralization-helpers.Rd @@ -17,6 +17,20 @@ anything. See examples below.} } \description{ Pluralization helper functions +} +\examples{ +nfile <- 0; cli_text("Found {no(nfile)} file{?s}.") + +#> Found no files. + +nfile <- 1; cli_text("Found {no(nfile)} file{?s}.") + +#> Found 1 file. + +nfile <- 2; cli_text("Found {no(nfile)} file{?s}.") + +#> Found 2 files. + } \seealso{ Other pluralization: From d74cb7ef26b3d5d8c90ae1670bdf5ddd59c1943e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A1bor=20Cs=C3=A1rdi?= Date: Wed, 28 Aug 2024 12:29:40 +0200 Subject: [PATCH 7/7] NEWS for using last for collapsing length-2 vectors if no sep2 --- NEWS.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/NEWS.md b/NEWS.md index 1d7f4ca47..1d6ba2ce6 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,9 @@ # cli (development version) +* `ansi_collapse()` and inline collapsing now uses `last` as the separator + (without the serial comma) for two-element vectors if `sep2` is not + given (@rundel, #681). + # cli 3.6.3 * cli now builds on ARM Windows.