Learn R Programming

assertive (version 0.2-1)

assert_all_are_uk_postcodes: Is the string a valid UK postcode?

Description

Checks that the input contains UK postcodes.

Usage

assert_all_are_uk_postcodes(x)

assert_any_are_uk_postcodes(x)

is_uk_postcode(x)

Arguments

x
Input to check.

Value

  • is_uk_postcode returns TRUE if the input string contains a valid UK postcode. The {assert_*} function returns nothing but throws an error when the is_* function returns FALSE.

References

Regexes taken from https://en.wikipedia.org/wiki/Postcodes_in_the_United_Kingdom#Validation.

Examples

Run this code
postcodes <- c(
  "SW1A 1AA", "SK11 9DW", "M34FP", "Le45ns", "TS25 2BZ", "gir 0aa"
)
is_uk_postcode(postcodes)
assert_all_are_uk_postcodes(postcodes)

Run the code above in your browser using DataLab