GithubHelp home page GithubHelp logo

joeroe / numerals Goto Github PK

View Code? Open in Web Editor NEW
1.0 3.0 0.0 432 KB

R package for numeric vectors with Unicode numerals

Home Page: https://numerals.joeroe.io

License: Other

R 100.00%
r r-package vctrs numerals arabic-numerals persian-numerals burmese-numerals bengali-numerals

numerals's Introduction

numerals

Project Status: Concept – Minimal or no implementation has been done yet, or the repository is only intended to be a limited example, demo, or proof-of-concept. CRAN status R-CMD-check

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] ٢٠

numerals's People

Contributors

joeroe avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

numerals's Issues

Right-to-left format method

R seems to have some support for right-to-left scripts, presumably picking up on the unicode bidi class, e.g.:

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

But it doesn't always happen when expected:

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

And it would also be nice if the indices and justification followed, something like this:

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

Write vignette

Including:

  • numeral class
  • Plotting with numerals
  • Reading/writing numerals
    • base write.* and write_* seem to work fine out of the box

numr_replace() or numr_substitute()?

Which to use as the default for formatting numerals? numr_replace() uses string replacement; numr_substitute() decomposes a numeric into digits and directly subsets the numerals matrix.

I was hoping numr_substitute() would be faster, but it isn't (yet):

library("numerals")

x <- floor(runif(1000) * 1e6)

bench::mark(
  numr_substitute(x, "fa")
)
#> Warning: Some expressions had a GC in every iteration; so filtering is disabled.
#> # A tibble: 1 x 6
#>   expression                    min   median `itr/sec` mem_alloc `gc/sec`
#>   <bch:expr>               <bch:tm> <bch:tm>     <dbl> <bch:byt>    <dbl>
#> 1 numr_substitute(x, "fa")   18.9ms     21ms      45.2        NA     68.7

bench::mark(
  numr_replace(x, "fa")
)
#> # A tibble: 1 x 6
#>   expression                 min   median `itr/sec` mem_alloc `gc/sec`
#>   <bch:expr>            <bch:tm> <bch:tm>     <dbl> <bch:byt>    <dbl>
#> 1 numr_replace(x, "fa")   8.51ms   8.54ms      112.        NA        0

But I do suspect numr_substitute() is more robust to e.g. character encoding and locale issues.

Add numeral systems

From https://en.wikipedia.org/wiki/List_of_numeral_systems:

  • Proto-cuneiform numerals
  • Proto-Elamite numerals
  • Sumerican numerals
  • Egyptian numerals
  • Elamite numerals
  • Indus numerals
  • Babylonian numerals
  • Chinese numerals
  • Japanese numerals
  • Korean numerals (Sino-Korean)
  • Vietnamese numerals (Sino-Vietnamese)
  • Aegean numerals
  • Bengali numerals
  • Roman numerals
  • Hebrew numerals
  • Indian numerals
    • Tamil numerals
    • Devanagari numerals
    • Tibetan numerals
  • Greek numerals
  • Phoenician numerals
  • Chinese rod numerals
  • Ge'ez numerals
  • Armenian numerals
  • Khmer numerals
  • Thai numerals
  • Abjad numerals
  • Eastern Arabic numerals
  • Persian numerals
  • Vietnamese numerals (Chữ Nôm)
  • Western Arabic numerals
  • Glagolitic numerals
  • Cyrillic numerals
  • Burmese numerals
  • Tangut numerals
  • Cistercian numerals
  • Maya numerals
  • Muisca numerals
  • Korean numerals (Hangul)
  • Aztec numerals
  • Sinhala numerals
  • Pentimal runes
  • Kaktovik Inupiaq numerals

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.