| assert_all_are_uk_postcodes {assertive.data.uk} | R Documentation |
Checks that the input contains UK postcodes.
assert_all_are_uk_postcodes(x, na_ignore = FALSE,
severity = getOption("assertive.severity", "stop"))
assert_any_are_uk_postcodes(x, na_ignore = FALSE,
severity = getOption("assertive.severity", "stop"))
is_uk_postcode(x)
x |
Input to check. |
na_ignore |
A logical value. If |
severity |
How severe should the consequences of the assertion be?
Either |
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.
The function doesn't guarantee that the postcode actually exists. It
should correctly return TRUE for genuine postcodes, and will weed out
most badly formatted strings and non-existent areas, but some non-existent
districts may incorrectly return TRUE. If you need 100
check against an up-to-date postcode database.
Regexes taken from https://en.wikipedia.org/wiki/Postcodes_in_the_United_Kingdom#Validation.
postcodes <- c( "SW1A 1AA", "SK11 9DW", "M34FP", "Le45ns", "TS25 2BZ", "gir 0aa" ) is_uk_postcode(postcodes) assert_all_are_uk_postcodes(postcodes)