Learn R Programming

numberize

numberize is an R package to convert numbers written as English, French or Spanish words from "zero" to "nine hundred and ninety nine trillion, nine hundred and ninety nine billion, nine hundred and ninety nine million, nine hundred and ninety nine thousand, nine hundred and ninety nine" to positive integer values.

numberize is developed at the Centre for the Mathematical Modelling of Infectious Diseases at the London School of Hygiene and Tropical Medicine as part of the Epiverse-TRACE program.

Installation

The package can be installed from CRAN using

install.packages("numberize")

Development version

You can install the development version of numberize from GitHub with:

pak::pak("epiverse-trace/numberize")

Example

These examples illustrate the current functionality.

library("numberize")

# numberize a French string
numberize("zéro", lang = "fr")
#> [1] 0

# numberize a Spanish string
numberize("Siete mil quinientos cuarenta y cinco", lang = "es")
#> [1] 7545

# numberize the English string "nine hundred and ninety-nine trillion, nine hundred and ninety-nine billion, nine hundred and ninety-nine million, nine hundred and ninety-nine thousand, nine hundred and ninety-nine" # nolint: line_length_linter.
formatC(numberize("nine hundred and ninety-nine trillion, nine hundred and ninety-nine billion, nine hundred and ninety-nine million, nine hundred and ninety-nine thousand, nine hundred and ninety-nine"), big.mark = ",", format = "fg") # nolint: line_length_linter.
#> [1] "999,999,999,999,999"

# some edge cases
numberize("veintiún", lang = "es")
#> [1] 21
numberize("veintiuno", lang = "es")
#> [1] 21

# convert a vector of written values
numberize(
  text = c(17, "dix", "soixante-cinq", "deux mille vingt-quatre", NA),
  lang = "fr"
)
#> [1]   17   10   65 2024   NA

Related packages and Limitations

  • {numberwang} converts numbers to words and vice versa. Limitation: English only, not on CRAN.
  • {nombre} converts numerics into words. Limitation: English only, no word to number conversion.
  • {english} converts numerics into words. Limitation: English only, no word to number conversion.
  • {spanish} converts numbers to words and vice versa. Limitation: Spanish only.

numberize is released as a standalone package in the hope that it will be useful to the R community at large. numberize was created in response to data cleaning requirements in {cleanepi}.

Lifecycle

This package is currently stable, as defined by the RECON software lifecycle.

Contributions

Contributions are welcome via pull requests.

Code of Conduct

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

Copy Link

Version

Install

install.packages('numberize')

Monthly Downloads

255

Version

1.0.2

License

MIT + file LICENSE

Issues

Pull Requests

Stars

Forks

Maintainer

Bankolé Ahadzie

Last Published

April 8th, 2025

Functions in numberize (1.0.2)

numberize

Convert a vector string of spelled numbers in a supported language to its numeric equivalent.
number_from

Generate a number from a numeric vector. Uses digits_from() output to generate the numeric value of the text.
digits_from

Generate a numeric vector from text in a supported language.
ambiguous

Test if a given numeric vector can have different meanings.