This function retrieves a list of countries where a specified currency is used. The function is case-insensitive and matches the currency name or part of the name. The output is ordered alphabetically by country name.
Value
A data frame containing the list of countries that use the specified currency, ordered alphabetically by country name. The columns include country codes (CCA2 and CCA3), common name, capital, continents, currency name, currency symbol, latitude, and longitude.
Note
The function utilizes the pre-loaded restcountries_data
dataset. Ensure that this dataset is loaded before invoking the function.
The function uses a case-insensitive regular expression to match the currency name, allowing partial matches.
Examples
# \donttest{
# Example usage: Find all countries that use the Euro
euro_countries <- get_countries_by_currency("Euro")
print(euro_countries)
#> # A tibble: 36 × 10
#> cca2 cca3 common_name capital continents currencies currency_name
#> <chr> <chr> <chr> <chr> <chr> <chr> <chr>
#> 1 AD AND Andorra Andorr… Europe Euro € Euro
#> 2 AT AUT Austria Vienna Europe Euro € Euro
#> 3 BE BEL Belgium Brusse… Europe Euro € Euro
#> 4 HR HRV Croatia Zagreb Europe Euro € Euro
#> 5 CY CYP Cyprus Nicosia Europe Euro € Euro
#> 6 EE EST Estonia Tallinn Europe Euro € Euro
#> 7 FI FIN Finland Helsin… Europe Euro € Euro
#> 8 FR FRA France Paris Europe Euro € Euro
#> 9 GF GUF French Guiana Cayenne South Ame… Euro € Euro
#> 10 TF ATF French Southern and … Port-a… Antarctica Euro € Euro
#> # ℹ 26 more rows
#> # ℹ 3 more variables: currency_symbol <chr>, lat <dbl>, lon <dbl>
# Example usage: Find all countries that use a currency with "dollar" in its name
dollar_countries <- get_countries_by_currency("dollar")
print(dollar_countries)
#> # A tibble: 58 × 10
#> cca2 cca3 common_name capital continents currencies currency_name
#> <chr> <chr> <chr> <chr> <chr> <chr> <chr>
#> 1 AS ASM American Samoa Pago P… Oceania United St… United State…
#> 2 AI AIA Anguilla The Va… North Ame… Eastern C… Eastern Cari…
#> 3 AG ATG Antigua and Barbuda Saint … North Ame… Eastern C… Eastern Cari…
#> 4 AU AUS Australia Canber… Oceania Australia… Australian d…
#> 5 BS BHS Bahamas Nassau North Ame… Bahamian … Bahamian dol…
#> 6 BB BRB Barbados Bridge… North Ame… Barbadian… Barbadian do…
#> 7 BZ BLZ Belize Belmop… North Ame… Belize do… Belize dollar
#> 8 BM BMU Bermuda Hamilt… North Ame… Bermudian… Bermudian do…
#> 9 IO IOT British Indian Ocean… Diego … Asia United St… United State…
#> 10 VG VGB British Virgin Islan… Road T… North Ame… United St… United State…
#> # ℹ 48 more rows
#> # ℹ 3 more variables: currency_symbol <chr>, lat <dbl>, lon <dbl>
# Example usage: Find all countries that use the Yen
yen_countries <- get_countries_by_currency("Yen")
print(yen_countries)
#> # A tibble: 1 × 10
#> cca2 cca3 common_name capital continents currencies currency_name
#> <chr> <chr> <chr> <chr> <chr> <chr> <chr>
#> 1 JP JPN Japan Tokyo Asia Japanese yen ¥ Japanese yen
#> # ℹ 3 more variables: currency_symbol <chr>, lat <dbl>, lon <dbl>
# }