Skip to contents

Append a/an to word

Usage

add_article(x)

Arguments

x

string or numeric value

Value

Returns a vector the same length as the input.

Details

This function uses crude logic to append 'a' or 'an' to numbers and phrases.

  • words that start with aeiou

  • negative numbers always start with 'a', ex: 'a -3' or 'a -8'

  • decimals always start with 'a' ex: 0.4 is usually pronounced 'a zero point four' or 'a point four'

  • numbers starting with 8 are always 'an'

  • if the integer that comes after thousand or million is 11 or 18 then 'an'

    • 18,000 becomes 18 and that becomes 'an 18'

  • if the integer that comes after thousand or million is in 1, 10, 12, 13, 14, 15, 16, 17, 19 then 'a'

    • 15,500 becomes 15 and that becomes 'a 15'

  • otherwise 'a'

Examples

add_article("increase")
#> [1] "an increase"

add_article("decrease")
#> [1] "a decrease"

add_article(c(1, 8, 10, 11, 18, 20, 80))
#> [1] "a 1"   "an 8"  "a 10"  "an 11" "an 18" "a 20"  "an 80"

add_article(18123)
#> [1] "an 18123"

stats::setNames(
  add_article(1.8 * 10^(1:7)),
  prettyNum(1.8 * 10^(1:7), big.mark = ",")
)
#>           18          180        1,800       18,000      180,000    1,800,000 
#>      "an 18"      "a 180"     "a 1800"   "an 18000"   "a 180000"  "a 1800000" 
#>      1.8e+07 
#> "an 1.8e+07"