ntimes_friendly {friendlynumber} | R Documentation |
Translate integer-ish numbers to a character vector of counts (once, twice, three times)
Description
Convert an integer vector, or numeric vector which is coercible to an integer without loss of precision, to a count (e.g. no times, once, twice, four times).
ntimes_friendly_safe()
checks that all arguments are of the correct type
and raises an informative error otherwise. ntimes_friendly()
does not
perform input validation to maximize its speed.
Usage
ntimes_friendly(
numbers,
one = "once",
two = "twice",
three = "three times",
zero = "no times",
na = "an unknown number of times",
nan = "an undefined number of times",
inf = "infinite times",
negative = "negative ",
and = FALSE,
hyphenate = TRUE
)
ntimes_friendly_safe(
numbers,
one = "once",
two = "twice",
three = "three times",
zero = "no times",
na = "an unknown number of times",
nan = "an undefined number of times",
inf = "infinite times",
negative = "negative ",
and = FALSE,
hyphenate = TRUE
)
Arguments
numbers |
An integer or integer-ish numeric vector to translate. |
one |
What to call values of |
two |
What to call values of |
three |
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. |
Value
A non-NA character vector of the same length as numbers
.
Examples
ntimes_friendly(c(0, 1, 2, 3, 22, 1001, NA, NaN, Inf, -Inf))
# Specify the translations of "special" numbers
ntimes_friendly(c(3, NA), three = "thrice", na = "some times")
# Modify the output formatting
ntimes_friendly(5678)
ntimes_friendly(5678, and = TRUE)
ntimes_friendly(5678, hyphenate = FALSE)
# Input validation
try(ntimes_friendly_safe(1234, and = " - "))