Learn R Programming

nombre (version 0.2.0)

cardinal: Convert numbers to cardinal character vectors (one, two, three)

Description

nom_card() and cardinal() produce cardinal numbers. nom_numer() and numerator() produce numerators. The results are equivalent for integers, but nom_card() and cardinal() support fractional components while nom_numer() and numerator() do not.

Usage

cardinal(
  x,
  max_n = getOption("nombre.max_n", Inf),
  negative = getOption("nombre.negative", "negative"),
  numerator = FALSE
)

nom_card( x, max_n = getOption("nombre.max_n", Inf), negative = getOption("nombre.negative", "negative"), numerator = FALSE )

numerator(x, ...)

nom_numer(x, ...)

Arguments

x

A numeric vector

max_n

A numeric vector. When the absolute value of x is greater than max_n, x remains numeric instead of being converted to words. If max_n is negative, no xs will be converted to words. (This can be useful when max_n is passed by another function.) Defaults to Inf, which converts all xs to words. Default can be changed by setting options("nombre.max_n").

negative

A character vector to append to negative numbers. Defaults to "negative". Default can be changed by setting options("nombre.negative").

numerator

When TRUE, an error is produced if x has a decimal or fractional component. Defaults to FALSE.

...

Additional arguments of numerator() are passed to cardinal()

Value

A character vector of the same length as x

See Also

Other number names: adverbial(), collective(), denominator(), ordinal()

Examples

Run this code
# NOT RUN {
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.")
# }

Run the code above in your browser using DataLab