Returns a text description for each phone number, in the language provided in locale.

get_geocode(x, home = NULL, strict = FALSE, locale = getOption("dialr.locale"))

Arguments

x

A phone vector.

home

ISO country code for home region. See Details.

strict

Should invalid phone numbers be removed? If TRUE, invalid phone numbers are replaced with NA.

locale

The Java locale used to retrieve localised results. The default is set in option dialr.locale.

Value

A text description for each phone number for the given locale, or "" if the number is invalid or could belong to multiple countries.

Details

The description might consist of the name of the country where the phone number is from, or the name of the geographical area the phone number is from if more detailed information is available.

If a phone number is from the region specified in home, only a lower-level description will be returned, if one exists. Otherwise, the phone number's region will be returned, with optionally some more detailed information.

For example, for a user from the region "US" (United States), we would show "Mountain View, CA" for a particular number, omitting the United States from the description. For a user from the United Kingdom (region "GB"), for the same number we may show "Mountain View, CA, United States" or even just "United States".

libphonenumber reference

get_geocode(): PhoneNumberOfflineGeocoder.getDescriptionForValidNumber().

Examples

x <- phone(c(0, 0123, "0412 345 678", "61412987654", "03 9123 4567", "+12015550123"), "AU")
get_geocode(x)
#> [1] NA           ""           ""           ""           "Australia" 
#> [6] "New Jersey"
get_geocode(x, strict = TRUE)
#> [1] NA           NA           ""           ""           "Australia" 
#> [6] "New Jersey"

# Specify a home country
get_geocode(x, home = "AU")
#> [1] NA              ""              ""              ""             
#> [5] "Australia"     "United States"
get_geocode(x, home = "US")
#> [1] NA           ""           "Australia"  "Australia"  "Australia" 
#> [6] "New Jersey"

# Specify a language
get_geocode(x, home = "DE", locale = "de")
#> [1] NA                               ""                              
#> [3] "Australien"                     "Australien"                    
#> [5] "Australien"                     "Vereinigte Staaten von Amerika"