country_info | R Documentation |
This function is an interface for REST Countries API. It allows to request and download information about countries, such as: currency, capital city, language spoken, flag, neighbouring countries, and much more. NOTE: Internet access is needed to download information from the API. At times the API may be unstable or slow to respond.
country_info(
countries = NULL,
fields = NULL,
fuzzy_match = TRUE,
match_info = FALSE,
collapse = TRUE,
base_url = "restcountries.com:8080/v3.1/"
)
countries |
A vector of countries for which we wish to download information. The function also supports fuzzy matching capabilities to facilitate querying. Information is only returned for the 249 countries in the ISO standard |
fields |
Character vector indicating the fields to query. A description of the accepted fields can be found here. Alternatively, a list of accepted field names can be obtained with the function |
fuzzy_match |
Logical value indicating whether to allow fuzzy matching of country names. Default is |
match_info |
Logical value indicating whether to return information on country names matched to each input in |
collapse |
Logical value indicating whether to collapse multiple columns relating to a same field together. Default is |
base_url |
Base URL used to construct the API calls. The default is |
Returns the requested information about the countries in a table. The rows of the table correspond to entries in countries
, columns correspond to requested fields
.
list_fields, check_countries_api
# Run examples only if a connection to the API is available:
if (check_countries_api(warnings = FALSE)){
# The example below queries information on the currency used in Brazil, US and France:
info <- country_info(countries = "Brazil", fields = "capital")
# data for multiple countries can be requested
info <- country_info(countries = c("Brazil", "USA", "FR"), fields = "capital")
#' # Data can be returned for all countries by leaving - countries - empty
info <- country_info(fields = "capital")
# All available fields can be requested by leaving fields empty
info <- country_info(countries = c("Brazil", "USA", "FR"))
# All information for all countries can be downloaded by leaving both arguments empty
info <- country_info()
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.