https://github.com/socialresearchcentre/dialr
Parse, Format, and Validate International Phone Numbers in R
https://github.com/socialresearchcentre/dialr
cran libphonenumber r r-package rstats
Last synced: 14 days ago
JSON representation
Parse, Format, and Validate International Phone Numbers in R
- Host: GitHub
- URL: https://github.com/socialresearchcentre/dialr
- Owner: socialresearchcentre
- License: gpl-3.0
- Created: 2019-02-06T07:02:56.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2023-10-15T10:49:24.000Z (over 1 year ago)
- Last Synced: 2025-03-03T00:21:19.653Z (about 1 month ago)
- Topics: cran, libphonenumber, r, r-package, rstats
- Language: R
- Homepage: https://socialresearchcentre.github.io/dialr/
- Size: 2.83 MB
- Stars: 12
- Watchers: 4
- Forks: 1
- Open Issues: 4
-
Metadata Files:
- Readme: README.Rmd
- License: LICENSE.md
Awesome Lists containing this project
- jimsghstars - socialresearchcentre/dialr - Parse, Format, and Validate International Phone Numbers in R (R)
README
---
output: github_document
---```{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)
```[](https://lifecycle.r-lib.org/articles/stages.html#stable)
[](https://cran.r-project.org/package=dialr)
[](https://github.com/socialresearchcentre/dialr/actions/workflows/R-CMD-check.yaml)
[](https://codecov.io/github/socialresearchcentre/dialr?branch=master)## 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))
```