Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/indenkun/arabic2kansuji

arabic2kansuji is a package consisting of functions to convert Arabic numerals to Kansuji on R.
https://github.com/indenkun/arabic2kansuji

arabic-numerals convert kansuji r

Last synced: 16 days ago
JSON representation

arabic2kansuji is a package consisting of functions to convert Arabic numerals to Kansuji on R.

Awesome Lists containing this project

README

        

---
output: github_document
---

```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
```

# arabic2kansuji

`{arabic2kansuji}` is a package consisting of Simple functions to convert given Arabic numerals to "Kansuji" numerical figures that represent numbers written in Chinese characters.

## Installation

You can install the released version of `{arabic2kansuji}` from CRAN with:

```r
install.packages("arabic2kansuji")
```

and also, install the development version install from GitHub:

``` r
install.packages("remotes")
remotes::install_github("indenkun/arabic2kansuji")
```

## Example

load library.

```{r example}
library(arabic2kansuji)
```

### `arabic2kansuji`

`arabic2kansuji` is a function that converts Arabic numerals to Kansuji verbatim.

There is no need to enclose only half-width Arabic numerals with double-quotation marks.

```{r}
arabic2kansuji(1234567890)
```

If you give a string containing Arabic numerals, everything else is retained except the Arabic numerals to be converted. Strings containing Arabic numerals can be converted, but please enclose them in double-quotations

```{r}
arabic2kansuji("昭和64年は1989年1月7日までです。")
```

By default, it converts only half-width Arabic numerals, but you can also convert only full-width Arabic numerals or convert both full-width and half-width Arabic numerals to Kansuji by specifying arguments.

```{r}
# By default, full-width Arabic numerals will not be converted.
arabic2kansuji("東京都新宿区西新宿2丁目8−1")
# It can convert full-width Arabic numerals by providing an argument.
arabic2kansuji("東京都新宿区西新宿2丁目8−1", width = "full")
arabic2kansuji("全角アラビア数字123と半角アラビア数字123の混在も引数を指定すると変換できます。", width = "all")
```

By default, 0 is converted to rei (〇), but it can be converted to zero (零) by specifying an argument.

```{r}
arabic2kansuji("令和2年は2020年")
arabic2kansuji("令和2年は2020年", zero = "zero")
```

Since this function only replaces Arabic numerals with Kansuji verbatim, it cannot be converted by calculating 1234 as 千二百三十四. This feature is provided by the `arabic2kansuji_num` functions.

### `arabic2kansuji_num`

This `arabic2kansuji_num` calculates and converts a given number to a kanji value. For example, 1234 can be converted to 千二百三十四.

```{r}
arabic2kansuji_num(124271318)
```

However, currently only accept one half-width Arabic numerals.

Use `arabic2kansuji_num` if you want to convert two or more half-width Arabic numerals by calculating the number of Chinese characters. You can also use `arabic2kansuji_all` to convert full-width Arabic numerals (as a string) to Kansuji.

```{r, error=TRUE}
arabic2kansuji_num("124271318人")
```

Use `arabic2kansuji_all` to calculate and convert Arabic numerals to Kansuji while keeping the string in Arabic numerals containing the string.

For more than 17 digits, a warning is given because calculation processing may not be performed correctly due to problems on the R.

```{r}
arabic2kansuji_num(1234567890123456789)
```

Negative values are also supported. The notation will be 負Kansuji.

```{r}
arabic2kansuji_num(-123456789)
```

Too large values (more than 10 to the power of 20) cannot be calculated.

```{r, error=TRUE}
arabic2kansuji_num(100000000000000000000)
```

`arabic2kansuji_num` accepts two or more Arabic numerals, calculates and converts them to Kansuji.

```{r, error=TRUE}
x <- c(123, 456, 789)
arabic2kansuji_num(x)
```

### `arabic2kansuji_all`

`arabic2kansuji_num` only accepts half-width Arabic numbers, but `arabic2kansuji_all` can convert a string containing a half-width Arabic number to Kansuji and keep the string. `arabic2kansuji_all` can convert not only half-width Arabic numerals but also full-width Arabic numerals can be converted by specifying an argument. However, it is not possible to convert only the full-size Arabic numerals in the string and keep the half-size Arabic numerals.

```{r}
arabic2kansuji_all("昭和64年は1989年1月7日までです。")
arabic2kansuji_all("平成31年は2019年4月30日までです。")
arabic2kansuji_all("平成31年は2019年4月30日までです。", widths = "all")
```

`arabic2kansuji_all` can receive more than one string.

```{r}
x <- c("昭和64年は1989年1月7日までです。", "平成31年は2019年4月30日までです。")
arabic2kansuji_all(x)
```

`arabic2kansuji_all` can also convert Arabic numerals and Kansuji intended for digits to represent a single number, such as 1億2345万 intended for 一億二千三百四十五万. This is a kind of side effect that happens when Arabic numbers are converted to Kansuji because the readings are just the same.

```{r}
arabic2kansuji_all("1億2345万")
```

## Imports packages

* `{purrr}`
* `{stringr}`
* `{stats}`

## Known Issue

* `arabic2kansuji_all` a combination of Arabic and Kansuji representing a single number of digits, such as tens or billions, but not including the next upper tens or billions of digits, such as 12345万, which is intended to be 一億二千三百四十五万, would be valued at 一万二千三百四十五 in the Arabic numeral place and would not appear in the intended form. There is currently no error on this issue.

```{r}
arabic2kansuji_all("12345万")
```

* `arabic2kansuji_*` does not support conversion of values greater than one hundred quintillion. Entering a value greater than one hundred quintillion will return a warning message and NA.

```{r, error=TRUE}
arabic2kansuji_num(1e+20)
arabic2kansuji_all("100000000000000000000個")
```

## License

MIT.