assertive.data.uk (version 0.0-2)

assert_all_are_uk_national_insurance_numbers: Is the string a valid UK national insurance number?

Description

Checks that the input contains UK national insurance numbers.

Usage

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

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

is_uk_national_insurance_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_uk_national_insurance_number returns TRUE if the input string contains a valid UK national insurance number. The assert_* function returns nothing but throw an error when the is_* function returns FALSE.

References

Regex taken from http://www.regexlib.com/REDetails.aspx?regexp_id=527.

Examples

Run this code
# NOT RUN {
ni_numbers <- c(
  "AA 00 00 00 A", "AA 00 00 00", "AA000000A",                #ok
  "ZZ 99 99 99 M", "ZZ 99 99 99", "ZZ999999M",                
  "DA 00 00 00", "FA 00 00 00", "IA 00 00 00",                #bad first letter
  "QA 00 00 00", "UA 00 00 00", "VA 00 00 00",
  "AD 00 00 00", "AF 00 00 00", "AI 00 00 00", "AO 00 00 00", #bad second letter
  "AQ 00 00 00", "AU 00 00 00", "AV 00 00 00",
  "AA 00 00 00 E", "AA 00 00 00 G", "AA 00 00 00 H",          #bad final letter
  "AA 00 00 00 I", "AA 00 00 00 J", "AA 00 00 00 K",
  "AA 00 00 00 L", "AA 00 00 00 N", "AA 00 00 00 O",
  "AA 00 00 00 P", "AA 00 00 00 Q", "AA 00 00 00 R",
  "AA 00 00 00 S", "AA 00 00 00 T", "AA 00 00 00 U",
  "AA 00 00 00 V", "AA 00 00 00 W", "AA 00 00 00 X",
  "AA 00 00 00 Y", "AA 00 00 00 Z"    
)
is_uk_national_insurance_number(ni_numbers)
assert_any_are_uk_national_insurance_numbers(ni_numbers)
#These examples should fail.
assertive.base::dont_stop(assert_all_are_uk_national_insurance_numbers(ni_numbers))
# }

Run the code above in your browser using DataLab