quantifier_friendly {friendlynumber} | R Documentation |
Translate integer-ish numbers to a character vector of quantifiers (the, both, all three)
Description
Convert an integer vector, or numeric vector which is coercible to an integer without loss of precision, to a quantifier (e.g. no, the, every, all five).
quantifier_friendly_safe()
checks that all arguments are of the correct type
and raises an informative error otherwise. quantifier_friendly()
does not
perform input validation to maximize its speed.
Usage
quantifier_friendly(
numbers,
one = "the",
two = "both",
zero = "no",
na = "a missing",
nan = "an undefined",
inf = "every",
negative = "negative ",
and = FALSE,
hyphenate = TRUE,
bigmark = TRUE,
max_friendly = 100
)
quantifier_friendly_safe(
numbers,
one = "the",
two = "both",
zero = "no",
na = "a missing",
nan = "an undefined",
inf = "every",
negative = "negative ",
and = FALSE,
hyphenate = TRUE,
bigmark = TRUE,
max_friendly = 100
)
Arguments
numbers |
An integer or integer-ish numeric vector to translate. |
one |
What to call values of |
two |
What to call values of |
zero |
What to call values of |
na |
What to call values of |
nan |
What to call values of |
inf |
What to call values of |
negative |
A prefix added to the translation of negative elements of |
and |
Whether to insert an |
hyphenate |
Whether to hyphenate numbers 21 through 99 (e.g. |
bigmark |
Whether the thousands places of formatted numbers should be separated with
a comma (e.g. |
max_friendly |
The maximum number to convert to a numeral. Elements of Use the |
Value
A non-NA character vector of the same length as numbers
.
Examples
quantifier_friendly(c(0, 1, 2, 3, NA, NaN, Inf))
# The `negative` prefix appears after the `"all"` prefix
quantifier_friendly(-4)
# `-1` and `-2` are not translated using `one` and `two`
quantifier_friendly(c(1, 2, -1, -2), one = "the", two = "both")
# Suppress the translation of large numbers
quantifier_friendly(c(99, 1234), max_friendly = -Inf)
quantifier_friendly(c(99, 1234), max_friendly = 100)
quantifier_friendly(c(99, 1234), max_friendly = 1500)
# Specify the translations of "special" numbers
quantifier_friendly(c(1, Inf), one = "a", inf = "all")
# Arguments `one`, `two`, `inf`, etc. take precedence over `max_friendly`
quantifier_friendly(1:3, one = "one", two = "two", max_friendly = -1)
# Modify the output formatting
quantifier_friendly(1021, max_friendly = Inf)
quantifier_friendly(1021, and = TRUE, max_friendly = Inf)
quantifier_friendly(1021, hyphenate = FALSE, max_friendly = Inf)
quantifier_friendly(1021, bigmark = FALSE, max_friendly = 10)
quantifier_friendly(1021, bigmark = TRUE, max_friendly = 10)
# Input validation
try(quantifier_friendly_safe(1234, max_friendly = NA))