The vec_fmt_spelled_num() function

Let’s create a numeric vector for the next few examples:

num_vals <- c(1, 8, 23, 76, 0, -5, 200, NA)

Using vec_fmt_spelled_num() will create a character vector with values rendered as spelled-out numbers. Any NA values remain as NA values. The rendering context will be autodetected unless specified in the output argument (here, it is of the "plain" output type).

vec_fmt_spelled_num(num_vals)
[1] "one"          "eight"        "twenty-three" "seventy-six"  "zero"        
[6] "-5"           "200"          "NA"          
#> [1] "one"     "eight"     "twenty-three"  "seventy-six"  "zero"

If we are formatting for a different locale, we could supply the locale ID and let gt obtain a locale-specific set of spelled numbers:

vec_fmt_spelled_num(num_vals, locale = "af")
[1] "een"             "agt"             "drie-en-twintig" "ses-en-sewentig"
[5] "nul"             "-5"              "200"             "NA"             
#> [1] "een"     "agt"     "drie-en-twintig"     "ses-en-sewentig"

As a last example, one can wrap the values in a pattern with the pattern argument. Note here that NA values won’t have the pattern applied.

vec_fmt_spelled_num(num_vals, pattern = "{x}.")
[1] "one."          "eight."        "twenty-three." "seventy-six." 
[5] "zero."         "-5."           "200."          "NA"           
#> [1] "one."     "eight."     "twenty-three."  "seventy-six."  "zero."