ITADN
r-lib/cli/Issues

`pluralize` fails for values outside ±`.Machine$integer.max`

#773Openmarcusmunch 创建于 2025-05-22
M
marcusmunchcommented
When trying to compare integers (but not doubles) outside of ±`.Machine$integer.max`, R returns `NA`, causing `pluralize` to fail, as `qty != 1` cannot be properly evaluated. ``` r # This works (.Machine$integer.max + 1) != 1 #> [1] TRUE # ...but this does not as.integer(.Machine$integer.max + 1) != 1 #> Warning: NAs introduced by coercion to integer range #> [1] NA ``` ## <code>pluralize</code> reprex ```r cli::pluralize("{99} bug{?s} in the code") #> 99 bugs in the code n_bugs <- 99 cli::pluralize("{n_bugs} bug{?s} in the code") #> 99 bugs in the code cli::cli_inform(c("Take one down", "And patch it up", "You got")) #> Take one down #> And patch it up #> You got n_bugs <- .Machine$integer.max cli::pluralize("{n_bugs} bug{?s}") #> 2147483647 bugs cli::pluralize("...add one more and it breaks: {n_bugs + 1} bug{?s}") #> Warning in make_quantity(values$qty): NAs introduced by coercion to integer #> range #> Error in if (qty != 1) parts[1] else "": missing value where TRUE/FALSE needed cli::pluralize("It's only an issue when you actually have something to pluralize: {n_bugs^2}") #> It's only an issue when you actually have something to pluralize: 4611686014132420608 cli::pluralize("You can also go low: {-1L * .Machine$integer.max} bug{?s}") #> You can also go low: -2147483647 bugs cli::pluralize("...but not too low {-1L * .Machine$integer.max - 1} bug{?s}") #> Warning in make_quantity(values$qty): NAs introduced by coercion to integer #> range #> Error in if (qty != 1) parts[1] else "": missing value where TRUE/FALSE needed ``` <sup>Created on 2025-05-22 with [reprex v2.0.2](https://reprex.tidyverse.org)</sup> </details>
0 条评论