Skip to contents

Is it an ISO 3166-1 country code?

Usage

is_country_code(x)

Arguments

x

A character vector.

Value

Logical vector; TRUE for a valid alpha-2 country code (e.g. US).

Details

Case-insensitive lookup against the internal .iso3166_alpha2 table (built by data-raw/build_lookups.R from the ISOcodes package). Note this overlaps is_us_state() for shared two-letter codes (e.g. MT); guess_data_type()'s specificity ranking resolves such ties.

Examples

is_country_code(c("US", "gb", "ZZ", NA))
#> [1]  TRUE  TRUE FALSE    NA