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

Open
#773 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
55/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
r
Domain
cli

Research direction

Start by locating the pluralize implementation and its make_quantity path, which is named in the warning. Reproduce the reported positive and negative boundary cases, then verify that quantities outside R's integer range remain comparable and pluralize completes without an NA-related error.

Written by the indexing model from the issue text.

Description

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

Dominant language
R
Stars
726
Forks
94
Avg merge
3h 35m
Merged PRs (30d)
1

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from r-lib/cli

All issues in r-lib/cli

Similar issues

More R issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.