get_countries_by_region {tidycountries}R Documentation

get_countries_by_region

Description

This function retrieves a list of countries based on a specified region, subregion, or continent. The function is case-insensitive and orders the countries alphabetically by their common names. If the input does not match any region, subregion, or continent, the function provides a list of all available regions, subregions, and continents.

Usage

get_countries_by_region(country_region_value, geometry = FALSE)

Arguments

country_region_value

A character string representing the region, subregion, or continent. The input is case-insensitive.

geometry

Logical. If TRUE, includes spatial geometry data for each country (boundaries). Defaults to FALSE. When TRUE, an additional column for geographic boundaries is included.

Value

A data frame with information on countries within the specified region, subregion, or continent. If geometry = TRUE, the result includes a geometry column with boundary data. If no match is found, a message lists all available regions, subregions, and continents.

Note

This function returns relevant information on countries in a specified region. When geometry = TRUE, it returns an sf object, including spatial data.

Examples


# Example usage: Get a list of countries in Africa
africa_countries <- get_countries_by_region("Africa")
print(africa_countries)

# Example usage: Get countries in a specific continent with geometry included
western_europe_countries <- get_countries_by_region("Western Europe", geometry = TRUE)
print(western_europe_countries)

# Example usage: Get a list of countries in the continent of Asia
asia_countries <- get_countries_by_region("Asia")
print(asia_countries)



[Package tidycountries version 0.1.0 Index]