knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  fig.path = "man/figures/README-",
  out.width = "100%"
)

library(nombre)
library(ipa)
# remotes::install_github("GuangchuangYu/badger")
library(badger)

nombre

r badge_cran_release(color = "brightgreen") r badge_lifecycle("stable") r badge_license(color = "blueviolet") r badge_github_actions(action = "R-CMD-check") r badge_codecov() r badge_dependencies()

nombre (French) r sampa("/nO~bR/"): number
nombre (Spanish) r sampa("/\"nom.b4e/"): name
nombre: package to convert numbers to their names in R

nombre converts numeric vectors to character vectors of English words. You can use it to express numbers as cardinals (one, two, three) or ordinals (first, second, third), as well as numerators and denominators. nombre supports not just whole numbers, but also negatives, fractions, and ratios.

Installation

You can install the released version of nombre from CRAN with:

``` {r eval = FALSE} install.packages("nombre")

or the development version from GitHub with:

``` {r eval = FALSE}
# install.packages("remotes")
remotes::install_github("rossellhayes/nombre")

Usage

library(nombre)

nombre converts numerics into words:

nom_card(2)
nom_card(2L)
x <- rep(TRUE, 525600)
nom_card(length(x))

It also works for numeric vectors:

nom_card(8^(1:10))

nombre can also generate ordinals, adverbials, collectives, numerators and denominators:

nom_ord(1:5)
nom_adv(1:5)
nom_coll(1:5)
nom_numer(1:5)
nom_denom(1:5)
nom_denom(1:5, numerator = 1:5)

r emo::ji("shushing") (numerators are almost always the same as cardinals)

You can also add ordinal suffixes to numerics or arbitrary number-like strings:

nom_ord(1:5, cardinal = FALSE)
nom_ord(c("n", "dozen", "umpteen", "eleventy", "one zillion"))

It can also handle less common numerics, like negatives, fractions, and ratios:

nom_card(-2)
nom_card(9.75)
nom_ratio(0.25)
nom_ratio(3)

Math with nombres

nombre implements an S3 class that seamlessly decides when to treat nombres like characters and when to treat them like numerics.

x <- nom_card(25)
x
x + 2
sqrt(x)
x < 30
x == "twenty-five"

Reverse it

uncardinal() attempts to convert character vectors of cardinal number names to numerics.

uncardinal(c("twenty-five", "negative three", "infinity"))

Advantages r emo::ji("rocket")

nombre is implemented using vectorized base R and runs faster than alternatives like english:

bench::mark(as.character(nom_card(1:1000)), as.character(english::english(1:1000)))

Hex sticker image adapted from artwork by @allison_horst.

Hex sticker fonts are Source Sans by Adobe and Permanent Marker by Font Diner.

Please note that nombre is released with a Contributor Code of Conduct. By contributing to this project, you agree to abide by its terms.



rossellhayes/nombre documentation built on June 2, 2022, 10:22 a.m.