r-lib/cli

Feature request: positive/negative "pluralization"

Closed this issue · 1 comments

It would be cool if you could use the pluralization formatting to provide alternative text based on whether the preceding value is positive or negative.

For example, if the value is positive use the word "more". If the value is negative use the word "fewer".

diff <- 10
cli_alert_inform("Count has {diff} {?fewer/more} records")
#> Count has 10 more records

diff <- -5
cli_alert_inform("Count has {diff} {?fewer/more} records")
# either with or without negative symbol
#> Count has 5 fewer records
#> Count has -5 fewer records

I am not sure how common this is, but is would also interfere with the current pluralization.

Nevertheless you can already do this, which is not too bad:

diff <- 10
cli_alert("Count has {diff} {ifelse(diff < 0, 'fewer', 'more')} records.")
#> → Count has 10 more records.