Skip to content

pluralize fails for values outside ±.Machine$integer.max #773

@marcusmunch

Description

@marcusmunch

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.

# 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

pluralize reprex

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 not an issue if you aren't actually pluralizing something: n_bugs^2 is {n_bugs^2}")
#> It's not an issue if you aren't actually pluralizing something: n_bugs^2 is 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

Created on 2025-05-22 with reprex v2.0.2

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions