-
Notifications
You must be signed in to change notification settings - Fork 1
/
README.Rmd
144 lines (106 loc) · 3.48 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
---
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%"
)
library(nombre)
library(ipa)
# remotes::install_github("GuangchuangYu/badger")
library(badger)
```
# nombre <img src="man/figures/logo.png?raw=TRUE" align="right" height="138" />
<!-- badges: start -->
`r badge_cran_release(color = "brightgreen")`
`r badge_lifecycle("stable")`
`r badge_license(color = "blueviolet")`
`r badge_github_actions(action = "R-CMD-check")`
`r badge_codecov()`
`r badge_dependencies()`
<!-- badges: end -->
> *nombre* (French) `r sampa("/nO~bR/")`: number
> *nombre* (Spanish) `r sampa("/\"nom.b4e/")`: name
> `nombre`: package to convert numbers to their names in R
**nombre** converts numeric vectors to character vectors of English words.
You can use it to express numbers as cardinals (one, two, three) or ordinals (first, second, third), as well as numerators and denominators. **nombre** supports not just whole numbers, but also negatives, fractions, and ratios.
## Installation
You can install the released version of **nombre** from [CRAN](https://CRAN.R-project.org) with:
``` {r eval = FALSE}
install.packages("nombre")
```
or the development version from GitHub with:
``` {r eval = FALSE}
# install.packages("remotes")
remotes::install_github("rossellhayes/nombre")
```
## Usage
```{r include = FALSE}
library(nombre)
```
**nombre** converts numerics into words:
```{r}
nom_card(2)
nom_card(2L)
x <- rep(TRUE, 525600)
nom_card(length(x))
```
It also works for numeric vectors:
```{r}
nom_card(8^(1:10))
```
**nombre** can also generate ordinals, adverbials, collectives, numerators and denominators:
```{r}
nom_ord(1:5)
nom_adv(1:5)
nom_coll(1:5)
nom_numer(1:5)
nom_denom(1:5)
nom_denom(1:5, numerator = 1:5)
```
> `r emo::ji("shushing")` (numerators are almost always the same as cardinals)
You can also add ordinal suffixes to numerics or arbitrary number-like strings:
```{r}
nom_ord(1:5, cardinal = FALSE)
nom_ord(c("n", "dozen", "umpteen", "eleventy", "one zillion"))
```
It can also handle less common numerics, like negatives, fractions, and ratios:
```{r}
nom_card(-2)
nom_card(9.75)
nom_ratio(0.25)
nom_ratio(3)
```
### Math with nombres
**nombre** implements an S3 class that seamlessly decides when to treat nombres like characters and when to treat them like numerics.
```{r}
x <- nom_card(25)
x
x + 2
sqrt(x)
x < 30
x == "twenty-five"
```
### Reverse it
`uncardinal()` attempts to convert character vectors of cardinal number names to numerics.
```{r}
uncardinal(c("twenty-five", "negative three", "infinity"))
```
## Advantages `r emo::ji("rocket")`
**nombre** is implemented using vectorized base R and runs faster than alternatives like [**english**](https://CRAN.R-project.org/package=english):
```{r}
bench::mark(as.character(nom_card(1:1000)), as.character(english::english(1:1000)))
```
---
Hex sticker image adapted from artwork by
@[allison_horst](https://github.com/allisonhorst/stats-illustrations).
Hex sticker fonts are
[Source Sans by Adobe](https://github.com/adobe-fonts/source-sans) and
[Permanent Marker](https://www.fontsquirrel.com/fonts/permanent-marker)
by [Font Diner](https://fontdiner.com/).
Please note that **nombre** is released with a [Contributor Code of Conduct](https://contributor-covenant.org/version/2/0/CODE_OF_CONDUCT.html).
By contributing to this project, you agree to abide by its terms.