r-lib / cli

Tools for making beautiful & useful command line interfaces
https://cli.r-lib.org/
Other
625 stars 66 forks source link

Feature request: positive/negative "pluralization" #678

Closed k5cents closed 3 months ago

k5cents commented 3 months ago

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
gaborcsardi commented 3 months ago

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.