plu_ral {plu}R Documentation

Pluralize a phrase based on the length of a vector

Description

Pluralize a phrase based on the length of a vector

Usage

plu_ral(
  x,
  vector = NULL,
  n = NULL,
  pl = NULL,
  irregulars = c("moderate", "conservative", "liberal", "none"),
  replace_n = TRUE,
  open = "{",
  close = "}",
  n_fn = lifecycle::deprecated(),
  ...
)

ral(
  x,
  vector = NULL,
  n = NULL,
  pl = NULL,
  irregulars = c("moderate", "conservative", "liberal", "none"),
  replace_n = TRUE,
  open = "{",
  close = "}",
  n_fn = lifecycle::deprecated(),
  ...
)

Arguments

x

A character vector (or vector that can be coerced to character) of English words or phrase to be pluralized. See details for special sequences which are handled differently.

vector

A vector whose length determines n. Defaults to NULL.

n

A numeric vector which will determine the plurality of x. Defaults to length(vector). If specified, overrides vector.

pl

A logical vector indicating whether to use the plural form (if TRUE) or the singular form (if FALSE) of x. Defaults to FALSE when n is 1 or -1 and TRUE for all other values. If specified, overrides n.

irregulars

What level of irregularity to use in pluralization. "moderate" uses the most common pluralization. "conservative" uses the most common irregular plural if one exists, even if a regular plural is more common. "liberal" uses a regular plural if it exists, even if an irregular plural is more common. "none" attempts to apply regular noun pluralization rules to all words. See section "Irregular plurals" for more details. Defaults to "moderate". The default can be changed by setting options(plu.irregulars). See examples in ralize() for more details.

replace_n

A logical indicating whether to use special handling for "n". See details. Defaults to TRUE.

open, close

The opening and closing delimiters for special strings. See section "Special strings". Defaults to "{" and "}".

n_fn

[Deprecated]

...

[Deprecated]

Value

The character vector x altered to match the number of n

Irregular plurals

Many words in English have both regular and irregular plural forms. For example, the word "person" can be pluralized as "persons" or "people", and the word "formula" can be pluralized as "formulas" or "formulae". plu offers several options for how to handle words with multiple plurals.

Special strings

Certain strings in x receive special treatment.

See Also

plu_ralize() to convert an English word to its plural form.

Examples

plu::ral("apple", pl = FALSE)
plu::ral("apple", pl = TRUE)

plu::ral("apple", n = 1)
plu::ral("apple", n = 2)
plu::ral("apple", n = 0)
plu::ral("apple", n = -1)
plu::ral("apple", n = 0.5)

mon <- c("apple")
tue <- c("pear", "pear")

plu::ral("apple", mon)
plu::ral("pear", tue)

paste("Monday, the caterpillar ate", plu::ral("an apple", mon))
paste("Tuesday, the caterpillar ate", plu::ral("a pear", tue))

paste("Monday, the caterpillar visited", plu::ral("an {apple} tree", mon))
paste("Tuesday, the caterpillar visited", plu::ral("a {pear} tree", tue))

paste("Monday, the caterpillar ate", plu::ral("a {single|multiple} apple", mon))
paste("Tuesday, the caterpillar ate", plu::ral("a {single|multiple} pear", tue))

# Vectorized `n`
foods <- c("apple", "pear", "plum", "strawberry", "orange")
quantities <- c(1, 2, 3, 4, 5)
plu::ral(foods, n = quantities)
paste(
  "The caterpillar ate",
  and::and(paste(nombre::cardinal(quantities), plu::ral(foods, n = quantities)))
)

# Some words have a dual form, a specific form for quantities of two
paste("The caterpillar ate", plu::ral("{the|both|all of the} apple", mon))
paste("The caterpillar ate", plu::ral("{the|both|all of the} pear", tue))
paste("The caterpillar ate", plu::ral("{the|both|all of the} delicacy", foods))

# The string "n" will be replaced by the number used for pluralization
paste("The caterpillar ate", plu::ral("n apple", mon))
paste("The caterpillar ate", plu::ral("n delicacy", foods))

# Special brace strings
plu::ral("{one|two}", n = 1)
plu::ral("{one|two}", n = 2)

plu::ral("{one|two|more}", n = 1)
plu::ral("{one|two|more}", n = 2)
plu::ral("{one|two|more}", n = 3)
plu::ral("{one|two|more}", n = 50)

plu::ral("{one|two|three|more}", n = 1)
plu::ral("{one|two|three|more}", n = 2)
plu::ral("{one|two|three|more}", n = 3)
plu::ral("{one|two|three|more}", n = 50)
plu::ral("{one|two|three|more}", n = 0)
plu::ral("{one|two|three|more}", n = 1.5)

[Package plu version 0.3.0 Index]