
Get Key Country Information About Japan from the REST Countries API
Source:R/get_country_info_jp.R
get_country_info_jp.RdRetrieves selected, essential information about Japan using the REST Countries API. The function returns a tibble with core details such as population, area, capital, region, and official language(s).
See the API documentation at https://restcountries.com/. Example API usage: https://restcountries.com/v3.1/name/japan?fullText=true.
Source
REST Countries API: https://restcountries.com/
Value
A tibble with the following 8 columns, or NULL if the API is unavailable:
name_common: Common name of the country.name_official: Official name of the country.region: Geographical region.subregion: Subregion within the continent.capital: Capital city.area: Area in square kilometers.population: Population of the country.languages: Languages spoken in the country, as a comma-separated string.
Details
The function sends a GET request to the REST Countries API. If the API returns data for Japan,
the function extracts and returns selected fields as a tibble. If the request fails or
Japan is not found, it returns NULL and prints an informative message.
Examples
# \donttest{
# Requires internet connection
result <- get_country_info_jp()
if (!is.null(result)) {
print(result)
}
#> # A tibble: 1 × 8
#> name_common name_official region subregion capital area population languages
#> <chr> <chr> <chr> <chr> <chr> <dbl> <int> <chr>
#> 1 Japan Japan Asia Eastern … Tokyo 377930 123210000 Japanese
# }