assertive.data.us (version 0.0-2)

assert_all_are_us_telephone_numbers: Is the string a valid US telephone number?

Description

Checks that the input contains US/Canadian (NANPA) telephone numbers.

Usage

assert_all_are_us_telephone_numbers(x, na_ignore = FALSE,
  severity = getOption("assertive.severity", "stop"))

assert_any_are_us_telephone_numbers(x, na_ignore = FALSE, severity = getOption("assertive.severity", "stop"))

is_us_telephone_number(x)

Arguments

x

Input to check.

na_ignore

A logical value. If FALSE, NA values cause an error; otherwise they do not. Like na.rm in many stats package functions, except that the position of the failing values does not change.

severity

How severe should the consequences of the assertion be? Either "stop", "warning", "message", or "none".

Value

is_us_telephone_number returns TRUE if the input string contains a valid US telephone number. The assert_* functions return nothing but throw an error when the is_* function returns FALSE.

Examples

Run this code
# NOT RUN {
phone_numbers <- c(
  "12345678901",   #country code as 1 
  "+12345678901",  #country code as +1
  "0012345678901", #country code as 001
  "2345678901",    #no country code
  "10345678901",   #NPA can't begin 0 
  "11345678901",   #...or 1
  "12335678901",   #2nd, 3rd digits of NPA can't match
  "12340678901",   #NXX can't begin 0        
  "12341678901",   #...or 1
  "12345118901",   #2nd, 3rd digits of NXX can't be 11
  "1234567",       #NPA must be included               
  "12345678"      #ditto
)
is_us_telephone_number(phone_numbers)
# }

Run the code above in your browser using DataCamp Workspace