Examples for 'cli::pluralize'


String templating with pluralization

Aliases: pluralize

Keywords:

### ** Examples

## Don't show: 
if (requireNamespace("glue", quietly = TRUE)) (if (getRversion() >= "3.4") withAutoprint else force)({ # examplesIf
## End(Don't show)
# Regular plurals
nfile <- 0; pluralize("Found {nfile} file{?s}.")
nfile <- 1; pluralize("Found {nfile} file{?s}.")
nfile <- 2; pluralize("Found {nfile} file{?s}.")

# Irregular plurals
ndir <- 1; pluralize("Found {ndir} director{?y/ies}.")
ndir <- 5; pluralize("Found {ndir} director{?y/ies}.")

# Use 'no' instead of zero
nfile <- 0; pluralize("Found {no(nfile)} file{?s}.")
nfile <- 1; pluralize("Found {no(nfile)} file{?s}.")
nfile <- 2; pluralize("Found {no(nfile)} file{?s}.")

# Use the length of character vectors
pkgs <- "pkg1"
pluralize("Will remove the {pkgs} package{?s}.")
pkgs <- c("pkg1", "pkg2", "pkg3")
pluralize("Will remove the {pkgs} package{?s}.")

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}.")

# Multiple quantities
nfiles <- 3; ndirs <- 1
pluralize("Found {nfiles} file{?s} and {ndirs} director{?y/ies}")

# Explicit quantities
nupd <- 3; ntotal <- 10
cli_text("{nupd}/{ntotal} {qty(nupd)} file{?s} {?needs/need} updates")
## Don't show: 
}) # examplesIf
> 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.
> ndir <- 1
> pluralize("Found {ndir} director{?y/ies}.")
Found 1 directory.
> ndir <- 5
> pluralize("Found {ndir} director{?y/ies}.")
Found 5 directories.
> 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.
> 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}.")
Will remove no  packages.
> pkgs <- c("pkg1", "pkg2", "pkg3")
> pluralize("Will remove {?no/the/the} {pkgs} package{?s}.")
Will remove the pkg1, pkg2, and pkg3 packages.
> nfiles <- 3
> ndirs <- 1
> pluralize("Found {nfiles} file{?s} and {ndirs} director{?y/ies}")
Found 3 files and 1 directory
> nupd <- 3
> ntotal <- 10
> cli_text("{nupd}/{ntotal} {qty(nupd)} file{?s} {?needs/need} updates")
3/10 files need updates
## End(Don't show)

[Package cli version 3.6.3 Index]