Title: | Number Names |
Version: | 0.4.1 |
Description: | Converts numeric vectors to character vectors of English number names. Provides conversion to cardinals, ordinals, numerators, and denominators. Supports negative and non-integer numbers. |
License: | MIT + file LICENSE |
URL: | https://nombre.rossellhayes.com, https://github.com/rossellhayes/nombre |
BugReports: | https://github.com/rossellhayes/nombre/issues |
Depends: | R (≥ 2.10) |
Imports: | fracture (≥ 0.2.1) |
Suggests: | testthat (≥ 3.0.0) |
Encoding: | UTF-8 |
Language: | en-US |
RoxygenNote: | 7.2.0 |
Config/testthat/edition: | 3 |
NeedsCompilation: | no |
Packaged: | 2022-05-23 16:04:01 UTC; alex |
Author: | Alexander Rossell Hayes
|
Maintainer: | Alexander Rossell Hayes <alexander@rossellhayes.com> |
Repository: | CRAN |
Date/Publication: | 2022-05-23 16:20:02 UTC |
nombre: Number Names
Description
Converts numeric vectors to character vectors of English number names. Provides conversion to cardinals, ordinals, numerators, and denominators. Supports negative and non-integer numbers.
Author(s)
Maintainer: Alexander Rossell Hayes alexander@rossellhayes.com (ORCID) [copyright holder]
Other contributors:
Eli Pousson eli.pousson@gmail.com [contributor]
See Also
Useful links:
Report bugs at https://github.com/rossellhayes/nombre/issues
Convert numbers to adverbial character vectors (once, twice, three times)
Description
Convert numbers to adverbial character vectors (once, twice, three times)
Usage
adverbial(x, thrice = FALSE, ...)
nom_adv(x, thrice = FALSE, ...)
nom_times(x, thrice = FALSE, ...)
Arguments
x |
A numeric vector |
thrice |
A logical of length one.
If |
... |
Additional arguments passed to |
Value
A character vector of the same length as x
See Also
Other number names:
cardinal()
,
collective()
,
denominator()
,
numerator()
,
ordinal()
,
ratio()
Examples
nom_adv(1:4)
nom_adv(1:4, thrice = TRUE)
Convert numbers to cardinal character vectors (one, two, three)
Description
Convert numbers to cardinal character vectors (one, two, three)
Usage
cardinal(x, max_n = Inf, negative = "negative", ...)
nom_card(x, max_n = Inf, negative = "negative", ...)
Arguments
x |
A numeric vector |
max_n |
A numeric vector.
When the absolute value of |
negative |
A character vector to append to negative numbers.
Defaults to |
... |
Arguments passed on to
|
Value
A character vector of the same length as x
Fractions
Decimal components of x
are automatically converted to fractions by
fracture::frac_mat()
.
See Also
uncardinal()
to convert character vectors to numbers
Other number names:
adverbial()
,
collective()
,
denominator()
,
numerator()
,
ordinal()
,
ratio()
Examples
nom_card(2)
nom_card(1:10)
nom_card(2 + 4/9)
nom_card(-2)
nom_card(-2, negative = "minus")
nom_card(5:15, max_n = 10)
paste("There are", nom_card(525600), "minutes in a year.")
paste("There are", nom_card(3.72e13), "cells in the human body.")
nom_card(1 / 2^(1:4))
nom_card(1 / 2^(1:4), common_denom = TRUE)
nom_card(1 / 2^(1:4), base_10 = TRUE)
nom_card(1 / 2^(1:4), base_10 = TRUE, common_denom = TRUE)
nom_card(1 / 2:5)
nom_card(1 / 2:5, base_10 = TRUE)
nom_card(1 / 2:5, base_10 = TRUE, max_denom = 100)
Convert numbers to collective character vectors (the, both, all three)
Description
Convert numbers to collective character vectors (the, both, all three)
Usage
collective(x, all_n = TRUE, of_the = FALSE, cardinal = TRUE, ...)
nom_coll(x, all_n = TRUE, of_the = FALSE, cardinal = TRUE, ...)
Arguments
x |
A numeric vector. |
all_n |
Whether to include the cardinal number after "all" for
collectives of 3 or more.
Defaults to |
of_the |
Whether to include "of the" for collectives other than 1.
Defaults to |
cardinal |
Whether to convert the number after "all" with |
... |
Additional arguments passed to |
Value
A character vector of the same length as x
.
See Also
Other number names:
adverbial()
,
cardinal()
,
denominator()
,
numerator()
,
ordinal()
,
ratio()
Examples
paste(nom_coll(0:3), "fish")
paste(nom_coll(9:12, max_n = 10), "fish")
Convert numbers to denominator character vectors (whole, half, third)
Description
Convert numbers to denominator character vectors (whole, half, third)
Usage
denominator(x, numerator = 1, quarter = TRUE, ...)
nom_denom(x, numerator = 1, quarter = TRUE, ...)
Arguments
x |
A numeric vector |
numerator |
A numeric vector.
The numerator(s) associated with the denominator(s).
When |
quarter |
A logical of length one.
If |
... |
Additional arguments passed to |
Value
A character vector of the same length as x
See Also
Other number names:
adverbial()
,
cardinal()
,
collective()
,
numerator()
,
ordinal()
,
ratio()
Examples
nom_denom(2)
nom_denom(1:10)
nom_denom(1:10, numerator = 2)
nom_denom(1:10, numerator = 1:10)
nom_denom(4)
nom_denom(4, quarter = FALSE)
nom_denom(1:10, numerator = 2, cardinal = FALSE)
nom_denom(5:15, numerator = 2, max_n = 10)
Convert numbers to numerator character vectors (one, two, three)
Description
nom_numer()
and numerator()
are equivalent to nom_card()
and
cardinal()
for integers, but cardinals support fractional components
while numerator
s do not.
Usage
numerator(x, ...)
nom_numer(x, ...)
Arguments
x |
A numeric vector |
... |
Additional arguments passed to |
See Also
Other number names:
adverbial()
,
cardinal()
,
collective()
,
denominator()
,
ordinal()
,
ratio()
Convert numbers to ordinal character vectors (first, second, third)
Description
Adds ordinal suffixes to numbers (or a character vector of number-like
words).
Converts numeric vectors to cardinal numbers before adding prefixes unless
cardinal
is FALSE
.
Usage
ordinal(x, cardinal = TRUE, ...)
nom_ord(x, cardinal = TRUE, ...)
Arguments
x |
A numeric or character vector. |
cardinal |
Whether to convert a numeric vector with |
... |
Further arguments passed to |
Value
A character vector of the same length as x
See Also
Other number names:
adverbial()
,
cardinal()
,
collective()
,
denominator()
,
numerator()
,
ratio()
Examples
nom_ord(2)
nom_ord(1:10)
nom_ord(525600)
nom_ord(1:10, cardinal = FALSE)
nom_ord(5:15, max_n = 10)
nom_ord(c("n", "dozen", "umpteen", "eleventy", "one zillion"))
nom_ord(9 + 3/4)
Convert numbers to ratio character vectors (two to one, one in three, five out of ten)
Description
Convert numbers to ratio character vectors (two to one, one in three, five out of ten)
Usage
ratio(x, sep = "in", max_n = Inf, negative = "negative", ...)
nom_ratio(x, sep = "in", max_n = Inf, negative = "negative", ...)
Arguments
x |
A numeric vector |
sep |
A character vector separating components of the ratio.
Defaults to |
max_n |
A numeric vector.
When the absolute value of |
negative |
A character vector to append to negative numbers.
Defaults to |
... |
Arguments passed on to
|
Details
x
is converted to a fraction by fracture::frac_mat()
.
Value
A character vector of the same length as x
See Also
Other number names:
adverbial()
,
cardinal()
,
collective()
,
denominator()
,
numerator()
,
ordinal()
Examples
paste0("Our team is outnumbered ", nom_ratio(10), ".")
paste0("The chances of winning are ", nom_ratio(1/1000000, sep = "in"), ".")
nom_ratio(c(1, 10, 100))
nom_ratio(c(0, 0.5, 1.5))
nom_ratio(c(0, 0.125, 0.625, 1), sep = "out of", common_denom = TRUE)
nom_ratio(5 / 10, sep = "in", base_10 = TRUE)
nom_ratio(6 / 25, sep = "in")
nom_ratio(6 / 25, sep = "out of", max_denom = 10)
Convert cardinal character vectors to numbers
Description
This function is in experimental development. It currently only supports English cardinal integers or character vectors produced by one of nombre's functions.
Usage
uncardinal(x)
nom_uncard(x)
Arguments
x |
A character vector of the cardinal names of numbers |
Value
A numeric vector the same length as n
.
NAs will be produced for numbers with fractions or decimals or non-cardinal
numbers (e.g. ordinals).
See Also
cardinal()
to convert numeric vectors to number names
Examples
uncardinal("one")
uncardinal("negative one hundred fifty-seven")
uncardinal(
c(
"twenty-five",
"one million two hundred thirty-four thousand five hundred sixty-seven"
)
)
uncardinal("infinity")
card <- cardinal(25)
uncardinal(card)
ord <- ordinal(25)
uncardinal(ord)