-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathREADME.Rmd
85 lines (66 loc) · 2.73 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
---
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%"
)
# load dplyr here to avoid mask warnings
library(dplyr, warn.conflicts = FALSE)
```
# dialr <a href='https://socialresearchcentre.github.io/dialr/'><img src='man/figures/logo.png' align="right" height="139" /></a>
<!-- badges: start -->
[![Lifecycle: stable](https://img.shields.io/badge/lifecycle-stable-brightgreen.svg)](https://lifecycle.r-lib.org/articles/stages.html#stable)
[![CRAN status](https://www.r-pkg.org/badges/version/dialr)](https://cran.r-project.org/package=dialr)
[![R-CMD-check](https://github.com/socialresearchcentre/dialr/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/socialresearchcentre/dialr/actions/workflows/R-CMD-check.yaml)
[![Coverage status](https://codecov.io/gh/socialresearchcentre/dialr/branch/master/graph/badge.svg)](https://codecov.io/github/socialresearchcentre/dialr?branch=master)
<!-- badges: end -->
## Overview
dialr is an R interface to [Google's libphonenumber
library](https://github.com/google/libphonenumber). It uses the java
implementation of libphonenumber via rJava for all phone number processing.
For a full rundown of libphonenumber see their
[GitHub](https://github.com/google/libphonenumber) and
[javadocs](https://javadoc.io/doc/com.googlecode.libphonenumber/libphonenumber/).
## Installation
You can install the released version of dialr from
[CRAN](https://CRAN.R-project.org) with:
``` r
install.packages("dialr")
```
And the development version from [GitHub](https://github.com/) with:
``` r
# install.packages("devtools")
devtools::install_github("socialresearchcentre/dialr")
```
## Usage
```{r}
library(dialr)
# Parse a character phone number vector
x <- c(0, 0123, "0404 753 123", "61410123817", "+12015550123")
x <- phone(x, "AU")
is_parsed(x) # Was the phone number successfully parsed?
is_valid(x) # Is the phone number valid?
is_possible(x) # Is the phone number possible?
get_region(x) # What region (ISO country code) is the phone number from?
get_type(x) # Is the phone number a fixed line, mobile etc.
format(x)
format(x, home = "AU")
# Use with dplyr
library(dplyr)
y <- tibble(id = 1:4,
phone1 = c(0, 0123, "0404 753 123", "61410123817"),
phone2 = c("03 9388 1234", 1234, "+12015550123", 0),
country = c("AU", "AU", "AU", "AU"))
y %>%
mutate_at(vars(matches("^phone")), ~phone(., country)) %>%
mutate_at(vars(matches("^phone")),
list(valid = is_valid,
region = get_region,
type = get_type,
clean = format))
```