Skip to content

Conversation

gaborcsardi
Copy link
Member

@gaborcsardi gaborcsardi commented Jun 10, 2020

With the usual syntax and collapsed vectors.

> # Regular plurals
> nfile <- 0; pluralize("Found {nfile} file{?s}.")
Found 0 files.
> nfile <- 1; pluralize("Found {nfile} file{?s}.")
Found 1 file.
> nfile <- 2; pluralize("Found {nfile} file{?s}.")
Found 2 files.
> 
> # Irregular plurals
> ndir <- 1; pluralize("Found {ndir} director{?y/ies}.")
Found 1 directory.
> ndir <- 5; pluralize("Found {ndir} director{?y/ies}.")
Found 5 directories.
> 
> # Use 'no' instead of zero
> nfile <- 0; pluralize("Found {no(nfile)} file{?s}.")
Found no files.
> nfile <- 1; pluralize("Found {no(nfile)} file{?s}.")
Found 1 file.
> nfile <- 2; pluralize("Found {no(nfile)} file{?s}.")
Found 2 files.
> 
> # Use the length of character vectors
> pkgs <- "pkg1"
> pluralize("Will remove the {pkgs} package{?s}.")
Will remove the pkg1 package.
> pkgs <- c("pkg1", "pkg2", "pkg3")
> pluralize("Will remove the {pkgs} package{?s}.")
Will remove the pkg1, pkg2, and pkg3 packages.
> 
> pkgs <- character()
> pluralize("Will remove {?no/the/the} {pkgs} package{?s}.")

> pkgs <- c("pkg1", "pkg2", "pkg3")
> pluralize("Will remove {?no/the/the} {pkgs} package{?s}.")
Will remove the pkg1, pkg2, and pkg3 packages.
> 
> # Multiple quantities
> nfiles <- 3; ndirs <- 1
> pluralize("Found {nfiles} file{?s} and {ndirs} director{?y/ies}")
Found 3 files and 1 directory
> 
> # Explicit quantities
> nupd <- 3; ntotal <- 10
> cli_text("{nupd}/{ntotal} {qty(nupd)} file{?s} {?needs/need} updates")
3/10 files need updates

Closes #152.

@codecov-commenter
Copy link

codecov-commenter commented Jun 10, 2020

Codecov Report

Merging #155 into master will increase coverage by 0.27%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #155      +/-   ##
==========================================
+ Coverage   79.34%   79.61%   +0.27%     
==========================================
  Files          30       30              
  Lines        1491     1511      +20     
==========================================
+ Hits         1183     1203      +20     
  Misses        308      308              
Impacted Files Coverage Δ
R/pluralize.R 88.52% <100.00%> (+5.59%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 262de73...0edbd63. Read the comment docs.

@gaborcsardi gaborcsardi merged commit 5e186a0 into master Sep 30, 2020
@gaborcsardi gaborcsardi deleted the feature/pluralize branch September 30, 2020 14:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Expose or repackage useful formatters (e.g. pluralization)
2 participants