Skip to contents

numerals is an R package that extends the base numeric types with methods for printing using Unicode digits in other numeral systems. It currently supports Eastern Arabic ("ar"), Bengali ("bn"), Persian ("fa"), and Burmese ("my") numerals.

Installation

You can install the development version of numerals from GitHub using devtools:

# install.package("devtools")
devtools::install_github("joeroe/numerals")

numerals has not yet been released on CRAN.

Usage

numeral() creates a numeric vector which is printed in another numeral system:

library("numerals")
# Eastern Arabic numerals
numeral(1:10, "ar")
#> <numeral[10]>
#>  [1]  ١  ٢  ٣  ٤  ٥  ٦  ٧  ٨  ٩ ١٠

# Persian numerals
numeral(1:10, "fa")
#> <numeral[10]>
#>  [1]  ۱  ۲  ۳  ۴  ۵  ۶  ۷  ۸  ۹ ۱۰

Numerals are compatible with both base and tidyverse packages. For example, they are printed in data frames and tibbles:

library("tibble")
x <- data.frame(en = 1:10, ar = numeral(1:10, "ar"), fa = numeral(1:10, "fa"))

x
#>    en ar fa
#> 1   1  ١  ۱
#> 2   2  ٢  ۲
#> 3   3  ٣  ۳
#> 4   4  ٤  ۴
#> 5   5  ٥  ۵
#> 6   6  ٦  ۶
#> 7   7  ٧  ۷
#> 8   8  ٨  ۸
#> 9   9  ٩  ۹
#> 10 10 ١٠ ۱۰
as_tibble(x)
#> # A tibble: 10 × 3
#>       en     ar     fa
#>    <int> <numr> <numr>
#>  1     1      ١      ۱
#>  2     2      ٢      ۲
#>  3     3      ٣      ۳
#>  4     4      ٤      ۴
#>  5     5      ٥      ۵
#>  6     6      ٦      ۶
#>  7     7      ٧      ۷
#>  8     8      ٨      ۸
#>  9     9      ٩      ۹
#> 10    10     ١٠     ۱۰

Otherwise, numerals are freely coercible to base numerics and so can be used in calculations:

numeral(2, "ar") * 10
#> <numeral[1]>
#> [1] ٢٠