Learn R Programming

MexicoDataAPI

The MexicoDataAPI package provides a unified interface to access open data from the World Bank API and the REST Countries API, with a focus on Mexico. It allows users to retrieve up-to-date information on topics such as economic indicators, population figures, literacy rates, and unemployment levels, as well as basic geopolitical information.

In addition to API-access functions, the package includes a set of curated datasets related to Mexico. These cover areas such as air quality monitoring, state-level income surveys, postal abbreviations, election results, and regional forest classification.

MexicoDataAPI is intended to support users working with data related to Mexico by integrating international API sources with selected datasets from national and academic origins, in a single R package.

Installation

You can install the MexicoDataAPI package from CRAN with the following R function:


install.packages("MexicoDataAPI")

Usage

After installation, load the package and start exploring and using its functions and datasets.


library(MexicoDataAPI)

MexicoDataAPI Functions

  • get_mexico_cpi(): Get Mexico's Consumer Price Index (2010 = 100) from World Bank

  • get_mexico_gdp(): Get Mexico's GDP (Current US$) from World Bank

  • get_mexico_life_expectancy: Get Mexico's Life Expectancy from World Bank

  • get_mexico_literacy_rate(): Get Mexico's Literacy Rate (Age 15+) from World Bank

  • get_mexico_population(): Get Mexico's Population (Total) from World Bank

  • get_mexico_unemployment(): Get Mexico's Unemployment Rate from World Bank

  • get_country_info(): Get essential information about Mexico or any other country by its full name

Example: get_country_info("Mexico"),get_country_info("mexico"),get_country_info("Peru")

  • view_datasets_MexicoDataAPI(): Lists all curated datasets included in the MexicoDataAPI package

Dataset Suffixes

Each dataset in MexicoDataAPI is labeled with a suffix to indicate its structure and type:

  • _df: A standard data frame.

  • _tbl_df: A tibble data frame object.

  • _chr: A character object.

Datasets Included in MexicoDataAPI

In addition to API access functions, MexicoDataAPI provides several preloaded datasets related to Mexico’s environment, demographics, and public data. Here are some featured examples:

  • mexico_elections_df: Data frame containing a subset of the 2012 Mexico Elections Panel Study.

  • mex_income_2016_tbl_df: Tibble containing household-level income data and associated demographic characteristics from the 2016 ENIGH (Household Income and Expenditure Survey).

  • mexico_abb_chr: Character vector containing the official two- or three-letter postal abbreviations for the 32 federal entities of Mexico.

Example Code:


# Load the package
library(MexicoDataAPI)

# Selected, essential information about Mexico
get_country_info("Mexico")

# Get Mexico's Population (Total) from World Bank
get_mexico_population()

# Load a dataset
data("mex_income_2016_tbl_df")

# Shows six rows of the dataset
head(mex_income_2016_tbl_df)

# Display the structure of the dataset
str(mex_income_2016_tbl_df)

# Shows the whole dataset

View(mex_income_2016_tbl_df)

Copy Link

Version

Install

install.packages('MexicoDataAPI')

Version

0.1.0

License

GPL-3

Issues

Pull Requests

Stars

Forks

Maintainer

Renzo Caceres Rossi

Last Published

July 16th, 2025

Functions in MexicoDataAPI (0.1.0)

pollution_zones_df

Pollution Zones in Mexico City
mexico_elections_df

2012 Mexico Elections Panel Study
stations_sinaica_df

Air Quality Measuring Stations in Mexico (SINAICA)
mex_income_2016_tbl_df

Mexican Income Data (2016)
mexico_abb_chr

Postal Abbreviations for Mexico
mexico_states_df

Mexican States Demographics (2020)
get_mexico_unemployment

Get Mexico's Unemployment Rate from World Bank
chiapas_dry_forests_df

Productivity in Chiapas Dry Forests
get_mexico_literacy_rate

Get Mexico's Literacy Rate (Age 15+) from World Bank
get_mexico_life_expectancy

Get Mexico's Life Expectancy from World Bank
mex_income_2008_tbl_df

Mexican Income Data (2008)
MexicoDataAPI

MexicoDataAPI: Access Mexican Data via APIs and Curated Datasets
get_mexico_gdp

Get Mexico's GDP (Current US$) from World Bank
get_mexico_population

Get Mexico's Population (Total) from World Bank
get_mexico_cpi

Get Mexico's Consumer Price Index (2010 = 100) from World Bank
view_datasets_MexicoDataAPI

View Available Datasets in MexicoDataAPI
get_country_info

Get Key Country Information from the REST Countries API
pollution_stations_df

Pollution Measuring Stations in Mexico City