Pluralize phrases in R
plu provides a simplified way to dynamically generate plain-language messages in R when we can’t know beforehand whether a message will be singular or plural.
Pluralizes English phrases based on the length of an associated vector. Contains helper functions to create natural language lists from vectors and to include the length of a vector in natural language.
You can install the stable release of plu from CRAN with:
install.packages("plu")
You can install the development version of plu from GitHub with:
# install.packages("remotes")
::install_github("rossellhayes/plu") remotes
<- c(x %in% 1:3 ~ "low", x %in% 4:6 ~ "medium", "x %in% 7:9")
formulas1 <- c(x %in% 1:3 ~ "low", x %in% 4:6 ~ "medium", "x %in% 7:9", "high")
formulas2 <- Filter(function(x) !rlang::is_formula(x), formulas1)
problems1 <- Filter(function(x) !rlang::is_formula(x), formulas2)
problems2
paste(
"All arguments must be formulas.",
::ral("Argument", problems1),
plu::stick(problems1),
plu::ral("isn't a formula.", problems1)
plu
)#> [1] "All arguments must be formulas. Argument x %in% 7:9 isn't a formula."
paste(
"All arguments must be formulas.",
::ral("Argument", problems2),
plu::stick(sapply(problems2, encodeString, quote = "`")),
plu::ral("isn't a formula.", problems2)
plu
)#> [1] "All arguments must be formulas. Arguments `x %in% 7:9` and `high` aren't formulas."
<- as.integer(runif(20, -10, 10))
ints paste(
"All inputs must be non-negative.",
::stick(
plu::more(
plusapply(ints[ints < 0], encodeString, quote = "`"), type = "integer"
)
),::ral("is {negative}.", ints[ints < 0])
plu
)#> [1] "All inputs must be non-negative. `-3`, `-2`, `-5`, `-6`, `-9` and 6 more integers are negative."
Hex sticker font is Bodoni* by indestructible type*.
Image adapted from icon made by Freepik from flaticon.com.
Please note that the plu project is released with a Contributor Code of Conduct. By contributing to this project, you agree to abide by its terms.