Learn R Programming

ChileDataAPI (version 0.1.0)

get_country_info: Get Key Country Information from the REST Countries API

Description

Retrieves selected, essential information about Chile or any other country by its full name. The data is retrieved from the REST Countries API. See the API documentation at https://restcountries.com/. Example API usage: https://restcountries.com/v3.1/name/chile?fullText=true.

Usage

get_country_info(name)

Value

A data frame with 8 columns:

  • name_common: Common name of the country.

  • name_official: Official name of the country.

  • capital: Capital city.

  • region: Geographic region.

  • subregion: Subregion.

  • population: Total population.

  • area: Total area in square kilometers.

  • languages: Official languages, separated by commas.

Arguments

name

Full country name (common or official). For example: "Chile", "Peru", "France".

Details

This function returns readable details such as the country's common and official name, capital, region, subregion, population, area, and official languages.

The function sends a GET request to the REST Countries API. If the request is successful (HTTP 200), it parses the JSON and extracts the key fields. If the country is not found or there's an error, the function returns NULL with a user-friendly message.

See Also

Examples

Run this code
if (FALSE) {
get_country_info("Chile")
get_country_info("Japan")
get_country_info("France")
}

Run the code above in your browser using DataLab