-
Notifications
You must be signed in to change notification settings - Fork 0
/
README.Rmd
170 lines (115 loc) · 5.76 KB
/
README.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
---
output: github_document
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
```
# arabic2kansuji
<!-- badges: start -->
<!-- badges: end -->
`{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.