Skip to contents

This function retrieves information about countries based on a specified calling code or part of it. The input can be a root calling code, suffix, or a full calling code, and the function is case-insensitive.

Usage

get_country_by_calling_code(call_code)

Arguments

call_code

A character string representing the calling code, root calling code, or suffix. The input is case-insensitive.

Value

A data frame containing the list of countries that match the provided calling code. The columns include country codes (CCA2 and CCA3), common name, official name, capital, region, subregion, continents, currencies, calling code details (root, suffixes, and full calling code), and geographic coordinates (latitude and longitude).

Note

The function relies on the pre-loaded restcountries_data dataset. Ensure that this dataset is loaded before invoking the function. The function searches across the root calling code, suffixes, and full calling code using case-insensitive matching.

Examples

# \donttest{
# Example usage: Find country information by root calling code
us_info <- get_country_by_calling_code("+1")
print(us_info)
#> # A tibble: 344 × 14
#>    cca3  cca2  common_name     official_name capital region subregion continents
#>    <chr> <chr> <chr>           <chr>         <chr>   <chr>  <chr>     <chr>     
#>  1 AIA   AI    Anguilla        Anguilla      The Va… Ameri… Caribbean North Ame…
#>  2 ASM   AS    American Samoa  American Sam… Pago P… Ocean… Polynesia Oceania   
#>  3 ATG   AG    Antigua and Ba… Antigua and … Saint … Ameri… Caribbean North Ame…
#>  4 BHS   BS    Bahamas         Commonwealth… Nassau  Ameri… Caribbean North Ame…
#>  5 BMU   BM    Bermuda         Bermuda       Hamilt… Ameri… North Am… North Ame…
#>  6 BRB   BB    Barbados        Barbados      Bridge… Ameri… Caribbean North Ame…
#>  7 CAN   CA    Canada          Canada        Ottawa  Ameri… North Am… North Ame…
#>  8 CYM   KY    Cayman Islands  Cayman Islan… George… Ameri… Caribbean North Ame…
#>  9 DMA   DM    Dominica        Commonwealth… Roseau  Ameri… Caribbean North Ame…
#> 10 DOM   DO    Dominican Repu… Dominican Re… Santo … Ameri… Caribbean North Ame…
#> # ℹ 334 more rows
#> # ℹ 6 more variables: currencies <chr>, root <chr>, suffixes <chr>,
#> #   calling_code <chr>, lat <dbl>, lon <dbl>

# Example usage: Find country information by calling code suffix
uk_info <- get_country_by_calling_code("44")
print(uk_info)
#> # A tibble: 1 × 14
#>   cca3  cca2  common_name official_name      capital region subregion continents
#>   <chr> <chr> <chr>       <chr>              <chr>   <chr>  <chr>     <chr>     
#> 1 AGO   AO    Angola      Republic of Angola Luanda  Africa Middle A… Africa    
#> # ℹ 6 more variables: currencies <chr>, root <chr>, suffixes <chr>,
#> #   calling_code <chr>, lat <dbl>, lon <dbl>

# Example usage: Find country information by full calling code
india_info <- get_country_by_calling_code("+91")
print(india_info)
#> # A tibble: 1 × 14
#>   cca3  cca2  common_name official_name     capital  region subregion continents
#>   <chr> <chr> <chr>       <chr>             <chr>    <chr>  <chr>     <chr>     
#> 1 IND   IN    India       Republic of India New Del… Asia   Southern… Asia      
#> # ℹ 6 more variables: currencies <chr>, root <chr>, suffixes <chr>,
#> #   calling_code <chr>, lat <dbl>, lon <dbl>
# }