dialr-match: Phone number equality checks

dialr-matchR Documentation

Phone number equality checks

Description

Check if two vectors contain matching phone numbers. See Details section for a full list of match types. is_match() with default arguments is used to implement == and != for phone vectors.

is_match() accepts phone or atomic vectors. Atomic vectors are converted to character for comparison. Note that although they can contain formatting character vectors are not parsed with a default region, so they will only ever be an "EXACT_MATCH" if a country calling code is specified with + at the start. See Examples.

Usage

is_match(e1, e2, detailed = FALSE, strict = TRUE, not_number_na = TRUE)

Arguments

e1

A phone or character vector.

e2

A phone or character vector.

detailed

If FALSE, is_match() returns a logical vector. If TRUE, it returns a character vector with the match type. See Details section for possible return values.

strict

If TRUE, only "EXACT_MATCH" is treated as a match. If FALSE, "EXACT_MATCH", "NSN_MATCH" and "SHORT_NSN_MATCH" are all considered a match. Ignored if detailed = TRUE.

not_number_na

If TRUE, "NOT_A_NUMBER" is converted to NA.

Details

Possible return values for is_match(x, detailed = TRUE):

  • "EXACT_MATCH": The country_code, NSN, presence of a leading zero for Italian numbers and any extension present are the same.

  • "NSN_MATCH": Either or both values has no region specified, and the NSNs and extensions are the same.

  • "SHORT_NSN_MATCH": Either or both values has no region specified, or the region specified is the same, and one NSN could be a shorter version of the other number. This includes the case where one has an extension specified, and the other does not.

  • "NOT_A_NUMBER": One of the input phone numbers failed to parse.

  • "NO_MATCH": All others.

For example, the numbers ⁠+1 345 657 1234⁠ and ⁠657 1234⁠ are a "SHORT_NSN_MATCH". The numbers ⁠+1 345 657 1234⁠ and ⁠345 657⁠ are a "NO_MATCH".

Value

A logical or character vector.

libphonenumber reference

is_match(): PhoneNumberUtil.isNumberMatch()

See Also

Other phone functions: dialr-example, dialr-phone, dialr-region, dialr-type, dialr-valid, dialr

Examples

is_match(phone("0412 345 678", "AU"), phone("+61412345678", "AU"))

phone("0412 345 678", "AU") == phone("+61412345678", "AU")
phone("0412 345 678", "AU") != phone("+61412345678", "AU")

# character vectors are only fully specified with a country calling code
is_match("0412345678", "0412345678", detailed = TRUE)
is_match("+61412345678", "+61412345678", detailed = TRUE)

is_match(phone("0412345678", "AU"), "0412345678", detailed = TRUE)
is_match(phone("+61412345678", "AU"), "+61412345678", detailed = TRUE)

dialr documentation built on Oct. 17, 2023, 1:11 a.m.