Learn R Programming

friendlynumber (version 1.0.0)

biginteger_friendly: Translate a biginteger to a cardinal character vector

Description

Convert a <bignum_biginteger> to a cardinal numeral (e.g. one, two, three).

A bignum::biginteger() can store any integer (i.e. arbitrary precision), which is useful for manipulating numbers too large to be represented (accurately) in an <integer> or <numeric> vector.

biginteger_friendly_safe() checks that all arguments are of the correct type and raises an informative error otherwise. biginteger_friendly() does not perform input validation to maximize its speed.

Usage

biginteger_friendly(
  numbers,
  zero = "zero",
  na = "missing",
  nan = "not a number",
  inf = "infinity",
  negative = "negative ",
  and = FALSE,
  hyphenate = TRUE
)

biginteger_friendly_safe( numbers, zero = "zero", na = "missing", nan = "not a number", inf = "infinity", negative = "negative ", and = FALSE, hyphenate = TRUE )

Value

A non-NA character vector of the same length as numbers.

Arguments

numbers

[bignum_biginteger]

A bignum::biginteger() vector to translate.

zero

[character(1)]

What to call values of 0 in numbers (e.g. zero = "zero").

na

[character(1)]

What to call values of NA in numbers (e.g. na = "missing").

nan

[character(1)]

What to call values of NaN in numbers (e.g. nan = "undefined").

inf

[character(1)]

What to call values of Inf in numbers (e.g. inf = "infinity").

negative

[character(1)]

A prefix added to the translation of negative elements of numbers. negative is the string "negative " by default.

and

[TRUE / FALSE]

Whether to insert an " and " before the tens place of translated numbers. and is FALSE by default.

hyphenate

[TRUE / FALSE]

Whether to hyphenate numbers 21 through 99 (e.g. "twenty-one" vs. "twenty one"). hyphenate is TRUE by default.

Examples

Run this code
if (FALSE) { # requireNamespace("bignum", quietly = TRUE)
biginteger_friendly(bignum::biginteger(c(0, 1, 2, NA, 10001)))

# Specify the translations of "special" numbers
biginteger_friendly(bignum::biginteger(-10), negative = "minus ")
biginteger_friendly(bignum::biginteger(NA), na = "unknown")

# Modify the output formatting
biginteger_friendly(bignum::biginteger(9999))
biginteger_friendly(bignum::biginteger(9999), and = TRUE)
biginteger_friendly(bignum::biginteger(9999), hyphenate = FALSE)

# Translate large numbers
large <- bignum::biginteger(10L)^1001L
biginteger_friendly(large)

# Input validation
try(biginteger_friendly_safe(1L))
}

Run the code above in your browser using DataLab