Type: | Package |
Title: | Access Mexican Data via APIs and Curated Datasets |
Version: | 0.1.0 |
Maintainer: | Renzo Caceres Rossi <arenzocaceresrossi@gmail.com> |
Description: | Provides functions to access data from the 'World Bank API' and the 'REST Countries API', related to Mexico's economic indicators, population statistics, literacy rates, and international geopolitical information. Additionally, the package includes curated datasets related to Mexico, including air quality monitoring stations, pollution zones, income surveys, postal abbreviations, election studies, forest productivity, and demographic data by state. The package supports research and analysis focused on Mexico by integrating reliable global APIs with structured national datasets drawn from open and academic sources. For more details on the 'World Bank API', see https://datahelpdesk.worldbank.org/knowledgebase/articles/889392, and for the 'REST Countries API', see https://restcountries.com/. |
License: | GPL-3 |
URL: | https://github.com/lightbluetitan/mexicodataapi, https://lightbluetitan.github.io/mexicodataapi/ |
BugReports: | https://github.com/lightbluetitan/mexicodataapi/issues |
Encoding: | UTF-8 |
LazyData: | true |
Depends: | R (≥ 4.1.0) |
Imports: | utils, httr, jsonlite, dplyr, scales |
Suggests: | ggplot2, testthat (≥ 3.0.0), knitr, rmarkdown |
RoxygenNote: | 7.3.2 |
Config/testthat/edition: | 3 |
VignetteBuilder: | knitr |
NeedsCompilation: | no |
Packaged: | 2025-07-12 05:30:13 UTC; renzorossiv |
Author: | Renzo Caceres Rossi
|
Repository: | CRAN |
Date/Publication: | 2025-07-16 15:40:14 UTC |
MexicoDataAPI: Access Mexican Data via APIs and Curated Datasets
Description
This package provides functions to access data from the 'World Bank API' and the 'REST Countries API', related to Mexico's economic indicators, population statistics, literacy rates, and international geopolitical information. Additionally, the package includes curated datasets related to Mexico, including air quality monitoring stations, pollution zones, income surveys, postal abbreviations, election studies, forest productivity, and demographic data by state.
Details
MexicoDataAPI: Access Mexican Data via APIs and Curated Datasets
Access Mexican Data via APIs and Curated Datasets.
Author(s)
Maintainer: Renzo Caceres Rossi arenzocaceresrossi@gmail.com
See Also
Useful links:
Productivity in Chiapas Dry Forests
Description
This dataset, chiapas_dry_forests_df, is a data frame containing data on species richness and vegetation productivity (measured via NDVI) in the dry forests of Chiapas, Mexico. It includes 96 observations and 2 variables. These indicators are often used in ecological and environmental analyses to assess biodiversity and landscape productivity.
Usage
data(chiapas_dry_forests_df)
Format
A data frame with 96 observations and 2 variables:
- richness
Species richness (integer)
- ndvi
Normalized Difference Vegetation Index (NDVI), a measure of vegetation productivity (numeric)
Details
The dataset name has been kept as 'chiapas_dry_forests_df' to avoid confusion with other datasets in the R ecosystem. This naming convention helps distinguish this dataset as part of the MexicoDataAPI package and assists users in identifying its specific characteristics. The suffix 'df' indicates that the dataset is a data frame. The original content has not been modified in any way.
Source
Data taken from the ADER package version 1.5
Get Key Country Information from the REST Countries API
Description
Retrieves selected, essential information about Mexico 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/mexico?fullText=true.
Usage
get_country_info(name)
Arguments
name |
Full country name (common or official). For example: "Mexico", "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.
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.
See Also
Examples
## Not run:
get_country_info("Mexico")
get_country_info("Japan")
get_country_info("France")
## End(Not run)
Get Mexico's Consumer Price Index (2010 = 100) from World Bank
Description
Retrieves Mexico's Consumer Price Index (CPI) using 2010 as the base year, for the years 2010 to 2022 from the World Bank Open Data API. The indicator used is 'FP.CPI.TOTL'.
Usage
get_mexico_cpi()
Details
The function sends a GET request to the World Bank API. If the API request fails or returns an error status code, the function returns 'NULL' with an informative message.
Value
A tibble with four columns:
- indicator
Indicator name (e.g., "Consumer price index (2010 = 100)")
- country
Country name ("Mexico")
- year
Year of the data (integer)
- value
Consumer Price Index value (numeric)
Note
Requires internet connection. Data is retrieved in real time from the World Bank API.
See Also
Examples
if (interactive()) {
get_mexico_cpi()
}
Get Mexico's GDP (Current US$) from World Bank
Description
Retrieves Mexico's Gross Domestic Product (GDP) in current US dollars for the years 2010 to 2022 using the World Bank Open Data API. The indicator used is 'NY.GDP.MKTP.CD'.
Usage
get_mexico_gdp()
Details
The function sends a GET request to the World Bank API. If the API request fails or returns an error status code, the function returns 'NULL' with an informative message.
Value
A tibble with the following columns:
- indicator
Indicator name (e.g., "GDP (current US$)")
- country
Country name ("Mexico")
- year
Year of the data (integer)
- value
GDP value in numeric form
- value_label
Formatted GDP value (e.g., "1,466,464,899,304")
Note
Requires internet connection. The data is retrieved in real time from the World Bank API.
See Also
GET, fromJSON, as_tibble, comma
Examples
if (interactive()) {
get_mexico_gdp()
}
Get Mexico's Life Expectancy from World Bank
Description
Retrieves Mexico's life expectancy at birth (in years) for the years 2010 to 2022 using the World Bank Open Data API. The indicator used is 'SP.DYN.LE00.IN'.
Usage
get_mexico_life_expectancy()
Details
The function sends a GET request to the World Bank API. If the API request fails or returns an error status code, the function returns 'NULL' with a message.
Value
A tibble with the following columns:
- indicator
Indicator name (e.g., "Life expectancy at birth, total (years)")
- country
Country name ("Mexico")
- year
Year of the data (integer)
- value
Life expectancy in years (numeric)
Note
Requires internet connection. Data is retrieved in real time from the World Bank API.
See Also
Examples
if (interactive()) {
get_mexico_life_expectancy()
}
Get Mexico's Literacy Rate (Age 15+) from World Bank
Description
This function retrieves Mexico's literacy rate for adults aged 15 and above,
expressed as a percentage, for the years 2010 to 2022 using the World Bank Open Data API.
The indicator used is SE.ADT.LITR.ZS
.
Usage
get_mexico_literacy_rate()
Value
A tibble with the following columns:
-
indicator
: Indicator name (e.g., "Literacy rate, adult total ( -
country
: Country name ("Mexico"). -
year
: Year of the data. -
value
: Literacy rate (numeric percentage).
Note
Some years may return missing values ('NA') due to lack of official data reported to the World Bank. Requires internet connection. The function pulls data in real time from the World Bank API.
See Also
Examples
## Not run:
get_mexico_literacy_rate()
## End(Not run)
Get Mexico's Population (Total) from World Bank
Description
Retrieves Mexico's total population for the years 2010 to 2022 using the World Bank Open Data API. The indicator used is 'SP.POP.TOTL'.
Usage
get_mexico_population()
Details
The function sends a GET request to the World Bank API. If the request fails or returns an error code, it will return 'NULL' with an informative message.
Value
A tibble with the following columns:
- indicator
Indicator name (e.g., "Population, total")
- country
Country name ("Mexico")
- year
Year of the data (integer)
- value
Population as numeric value
- value_label
Formatted population value (e.g., "126,705,138")
Note
Requires internet connection. Data is retrieved in real time from the World Bank API.
See Also
GET, fromJSON, as_tibble, comma
Examples
if (interactive()) {
get_mexico_population()
}
Get Mexico's Unemployment Rate from World Bank
Description
Retrieves Mexico's total unemployment rate as a percentage of the total labor force from 2010 to 2022 using the World Bank Open Data API.
Usage
get_mexico_unemployment()
Details
The function sends a GET request to the World Bank API. If the request fails or returns a status
other than 200, the function returns NULL
with an informative message.
Value
A tibble with four columns: 'indicator' (name of the indicator), 'country' (country name), 'year' (year of observation), and 'value' (unemployment rate as a numeric percentage).
Note
This function requires an internet connection.
See Also
Examples
## Not run:
get_mexico_unemployment()
## End(Not run)
Mexican Income Data (2008)
Description
This dataset, mex_income_2008_tbl_df, is a tibble containing household-level income data and associated demographic characteristics from the 2008 ENIGH (Household Income and Expenditure Survey) in Mexico. The dataset includes 5,000 observations and 8 variables, covering household number, income, household composition, education, domicile size, and age categories.
Usage
data(mex_income_2008_tbl_df)
Format
A tibble with 5,000 observations and 8 variables:
- hh_number
Household ID (character)
- factor
Expansion factor (integer)
- income
Household income (numeric)
- hh_structure
Household structure (factor with 5 levels)
- education
Education level of household members (factor with 11 levels)
- domicile_size
Size of domicile (factor with 4 levels)
- age
Age of household head (integer)
- age_cat
Categorical age group (factor with 7 levels)
Details
The dataset name has been kept as 'mex_income_2008_tbl_df' to avoid confusion with other datasets in the R ecosystem. This naming convention helps distinguish this dataset as part of the MexicoDataAPI package and assists users in identifying its specific characteristics. The suffix 'tbl_df' indicates that the dataset is a tibble data frame. The original content has not been modified in any way.
Source
Data taken from the dineq package version 0.1.0
Mexican Income Data (2016)
Description
This dataset, mex_income_2016_tbl_df, is a tibble containing household-level income data and associated demographic characteristics from the 2016 ENIGH (Household Income and Expenditure Survey) in Mexico. The dataset includes 5,000 observations and 8 variables, covering household number, income, household composition, education, domicile size, and age categories.
Usage
data(mex_income_2016_tbl_df)
Format
A tibble with 5,000 observations and 8 variables:
- hh_number
Household ID (character)
- factor
Expansion factor (integer)
- income
Household income (numeric)
- hh_structure
Household structure (factor with 5 levels)
- education
Education level of household members (factor with 11 levels)
- domicile_size
Size of domicile (factor with 4 levels)
- age
Age of household head (integer)
- age_cat
Categorical age group (factor with 7 levels)
Details
The dataset name has been kept as 'mex_income_2016_tbl_df' to avoid confusion with other datasets in the R ecosystem. This naming convention helps distinguish this dataset as part of the MexicoDataAPI package and assists users in identifying its specific characteristics. The suffix 'tbl_df' indicates that the dataset is a tibble data frame. The original content has not been modified in any way.
Source
Data taken from the dineq package version 0.1.0
Postal Abbreviations for Mexico
Description
This dataset, mexico_abb_chr, is a character vector containing the official two- or three-letter postal abbreviations for the 32 federal entities of Mexico. These abbreviations are commonly used in maps, postal services, and statistical reports.
Usage
data(mexico_abb_chr)
Format
A character vector with 32 elements:
- mexico_abb_chr
Character vector of 32 postal abbreviations (e.g., "AGU", "BCN", "DIF")
Details
The dataset name has been kept as mexico_abb_chr to avoid confusion with other datasets in the R ecosystem. This naming convention helps distinguish this dataset as part of the MexicoDataAPI package and assists users in identifying its specific characteristics. The suffix chr indicates that the dataset is a character vector. The original content has not been modified in any way.
Source
Data taken from the minimap package version 0.1.0
2012 Mexico Elections Panel Study
Description
This dataset, mexico_elections_df, is a data frame containing a subset of the 2012 Mexico Elections Panel Study. The dataset includes 1004 observations and 25 variables, covering demographics, political preferences, and attitudes toward electoral processes. It provides valuable insights into voter behavior and perceptions during the 2012 federal elections in Mexico.
Usage
data(mexico_elections_df)
Format
A data frame with 1004 observations and 25 variables:
- mex.t
Wave number (integer)
- mex.male
Gender: 1 = Male, 0 = Female (integer)
- mex.age
Age of respondent (numeric)
- mex.education
Level of education (integer)
- mex.y.all
Year variable (integer)
- mex.vote
Vote intention or behavior (integer)
- mex.age2
Age squared (numeric)
- mex.interest
Interest in politics (integer)
- mex.married
Marital status (integer)
- mex.pidpanw2
Partisan ID: PAN (integer)
- mex.pidprdw2
Partisan ID: PRD (integer)
- mex.pidpriw2
Partisan ID: PRI (integer)
- mex.votecard
Possession of voting card (integer)
- mex.urban
Urban residence indicator (integer)
- mex.cleanelections
Perception of clean elections (integer)
- mex.metro
Lives in metropolitan area (integer)
- mex.centralregion
Lives in central region (integer)
- mex.northregion
Lives in northern region (integer)
- mex.wealth
Wealth index (numeric)
- mex.epnapprove
Approval of electoral authority (integer)
- mex.havepropoganda
Received political propaganda (integer)
- mex.concurrent
Concurrent elections indicator (integer)
- mex.cleanelectionsmiss
Missing response for clean elections question (integer)
- mex.loyal
Party loyalty (integer)
- mex.direct
Direct benefit from party/government (integer)
Details
The dataset name has been kept as 'mexico_elections_df' to avoid confusion with other datasets in the R ecosystem. This naming convention helps distinguish this dataset as part of the MexicoDataAPI package and assists users in identifying its specific characteristics. The suffix 'df' indicates that the dataset is a data frame. The original content has not been modified in any way.
Source
Data taken from the list package version 9.2.6
Mexican States Demographics (2020)
Description
This dataset, mexico_states_df, is a data frame containing population estimates and demographic indicators for all 32 Mexican states in the year 2020. It includes total population, gender-specific counts, and the number of people who self-identify as Afro-Mexican or speak an indigenous language.
Usage
data(mexico_states_df)
Format
A data frame with 32 observations and 11 variables:
- region
Geographic region of the state (character)
- state_name
State name (character)
- state_name_official
Official state name (character)
- state_abbr
State abbreviation (character)
- state_abbr_official
Official state abbreviation (character)
- year
Year of the data (numeric)
- pop
Total population (integer)
- pop_male
Male population (integer)
- pop_female
Female population (integer)
- afromexican
Number of people who identify as Afro-Mexican (integer)
- indigenous_language
Number of people who speak an indigenous language (integer)
Details
The dataset name has been kept as 'mexico_states_df' to avoid confusion with other datasets in the R ecosystem. This naming convention helps distinguish this dataset as part of the MexicoDataAPI package and assists users in identifying its specific characteristics. The suffix 'df' indicates that the dataset is a data frame. The original content has not been modified in any way.
Source
Data taken from the MexBrewer package version 0.0.2
Pollution Measuring Stations in Mexico City
Description
This dataset, pollution_stations_df, is a data frame containing information about pollution measuring stations located in Mexico City. Each record corresponds to a station, including geographic coordinates and elevation. The station with code SS1 was manually added due to its absence in the original dataset; its location was identified through the Audit of Ambient Air Monitoring Stations for the Sistema de Monitoreo Atmosférico de la Ciudad de México.
Usage
data(pollution_stations_df)
Format
A data frame with 70 observations and 7 variables:
- station_code
Station identifier code (character)
- station_name
Name of the pollution station (character)
- lon
Longitude (numeric)
- lat
Latitude (numeric)
- altitude
Elevation above sea level in meters (integer)
- comment
Comments or notes (character)
- station_id
Numerical ID used for internal reference (numeric)
Details
The dataset name has been kept as 'pollution_stations_df' to avoid confusion with other datasets in the R ecosystem. This naming convention helps distinguish this dataset as part of the MexicoDataAPI package and assists users in identifying its specific characteristics. The suffix 'df' indicates that the dataset is a data frame. The original content has not been modified in any way.
Source
Data taken from the aire.zmvm package version 1.0.0
Pollution Zones in Mexico City
Description
This dataset, pollution_zones_df, is a data frame containing the municipios (counties) that compose the five geographic zones into which Mexico City was divided for the purpose of disseminating information about the IMECA (Índice Metropolitano de la Calidad del Aire).
Usage
data(pollution_zones_df)
Format
A data frame with 36 observations and 6 variables:
- region
Geographic region (character)
- state_code
State code (character)
- state_abbr
State abbreviation (character)
- municipio_code
Municipality code (character)
- municipio_name
Municipality name (character)
- zone
Air quality zone designation (character)
Details
The dataset name has been kept as pollution_zones_df to avoid confusion with other datasets in the R ecosystem. This naming convention helps distinguish this dataset as part of the MexicoDataAPI package and assists users in identifying its specific characteristics. The suffix 'df' indicates that the dataset is a data frame. The original content has not been modified in any way.
Source
Data taken from the aire.zmvm package version 1.0.0
Air Quality Measuring Stations in Mexico (SINAICA)
Description
This dataset, stations_sinaica_df, is a data frame containing information about air quality monitoring stations that report to the National Air Quality Information System (SINAICA) in Mexico. The dataset includes 365 observations and 26 variables, providing metadata on station identifiers, geolocation, network affiliations, operational status, and other attributes such as video links and validation dates.
Usage
data(stations_sinaica_df)
Format
A data frame with 365 observations and 26 variables:
- station_id
Station identifier (integer)
- station_name
Name of the station (character)
- station_code
Code of the station (character)
- network_id
Identifier of the network (integer)
- network_name
Name of the network (character)
- network_code
Code of the network (character)
- street
Street address (character)
- ext
External number (character)
- interior
Interior number (character)
- colonia
Colonia (neighborhood) name (character)
- zip
Postal code (character)
- state_code
State code (integer)
- municipio_code
Municipality code (integer)
- year_started
Year the station began operation (integer)
- altitude
Altitude of the station in meters (integer)
- address
Full address of the station (character)
- date_validated
Validation date (character)
- date_validated2
Second validation date (character)
- passed_validation
Indicates if the station passed validation (integer)
- video
Video URL or link (character)
- lat
Latitude (numeric)
- lon
Longitude (numeric)
- date_started
Date the station started operation (character)
- timezone
Timezone of the station (character)
- street_view
Street view URL or link (character)
- video_interior
Interior video URL or link (character)
Details
The dataset name has been kept as 'stations_sinaica_df' to avoid confusion with other datasets in the R ecosystem. This naming convention helps distinguish this dataset as part of the MexicoDataAPI package and assists users in identifying its specific characteristics. The suffix 'df' indicates that the dataset is a data frame. The original content has not been modified in any way.
Source
Data taken from the rsinaica package version 1.1.0
View Available Datasets in MexicoDataAPI
Description
This function lists all datasets available in the 'MexicoDataAPI' package. If the 'MexicoDataAPI' package is not loaded, it stops and shows an error message. If no datasets are available, it returns a message and an empty vector.
Usage
view_datasets_MexicoDataAPI()
Value
A character vector with the names of the available datasets. If no datasets are found, it returns an empty character vector.
Examples
if (requireNamespace("MexicoDataAPI", quietly = TRUE)) {
library(MexicoDataAPI)
view_datasets_MexicoDataAPI()
}