forked from verajosemanuel/ESmisc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathREADME.Rmd
58 lines (37 loc) · 2.34 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
---
output:
md_document:
variant: markdown_github
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
# words2number: Convert English number words into numeric digits [![Build Status](https://travis-ci.org/benmarwick/words2number.svg?branch=master)](https://travis-ci.org/benmarwick/words2number)
### Installation
```{r, eval=FALSE}
devtools::install_github("benmarwick/words2number")
```
This is a fork of [verajosemanuel/ESmisc](https://github.com/verajosemanuel/ESmisc), which is for Spanish numbers. I've changed the Spanish to English and made a few other minor modifications.
### How to use
The only function in this package, `to_number`, is a simple function to translate English words for whole number quantities into their numerical counterparts. Given a numerical quantity spelled in English, `to_number` translates it to an integer.
```{r message = FALSE, warning=FALSE}
library(words2number)
to_number("forty two")
to_number("forty-two")
to_number("fortytwo")
```
It can also handle ordinals:
```{r}
to_number("forty second")
to_number("forty-third")
to_number("fortyfourth")
```
### Usage notes
- `to_number` needs clean text. The input must be previously cleaned with extraneous words and symbols removed.
- Quantities must be written in simple, common English (this function is very simple).
- It currently doesn't handle decimals (e.g. "three point one") or fractions (e.g. "three-quarters")
- The upper limit is up to the millions range.
- There are some tests in the package already, but this is experimental, and there may be some numbers that it doesn't work on. Please let me know if you find them!
### Also relevant
If you want to go the other way, convert digits into English words, you can use the [english](https://cran.r-project.org/package=english) package. For example, `as.character(english::english(5))` will give "five". There is also `replace_number()` from the [textclean](https://cran.r-project.org/package=textclean) package. I took some inspiration for the ordinals from the [finnfiddle/words-to-numbers](https://github.com/finnfiddle/words-to-numbers) js library.
### Contributing
Please note that this project is released with a [Contributor Code of Conduct](CODE_OF_CONDUCT.md).
By participating in this project you agree to abide by its terms.