Type: | Package |
Title: | Access Peruvian Data via Public APIs and Curated Datasets |
Version: | 0.1.0 |
Maintainer: | Renzo Caceres Rossi <arenzocaceresrossi@gmail.com> |
Description: | Provides functions to access data from public RESTful APIs including 'Nager.Date', 'World Bank API', and 'REST Countries API', retrieving real-time or historical data related to Peru, such as holidays, economic indicators, and international demographic and geopolitical indicators. Additionally, the package includes curated datasets focused on Peru, covering topics such as administrative divisions, electoral data, demographics, biodiversity and educational classifications. The package supports reproducible research and teaching by integrating reliable international APIs and structured datasets from public, academic, and government sources. For more information on the APIs, see: 'Nager.Date' https://date.nager.at/Api, 'World Bank API' https://datahelpdesk.worldbank.org/knowledgebase/articles/889392, and 'REST Countries API' https://restcountries.com/. |
License: | MIT + file LICENSE |
Language: | en |
URL: | https://github.com/lightbluetitan/peruapis, https://lightbluetitan.github.io/peruapis/ |
BugReports: | https://github.com/lightbluetitan/peruapis/issues |
Encoding: | UTF-8 |
LazyData: | true |
Depends: | R (≥ 4.1.0) |
Imports: | utils, httr, jsonlite, dplyr, scales, tibble |
Suggests: | ggplot2, testthat (≥ 3.0.0), knitr, rmarkdown |
RoxygenNote: | 7.3.2 |
Config/testthat/edition: | 3 |
VignetteBuilder: | knitr |
NeedsCompilation: | no |
Packaged: | 2025-09-10 01:21:05 UTC; Renzo |
Author: | Renzo Caceres Rossi
|
Repository: | CRAN |
Date/Publication: | 2025-09-15 07:30:12 UTC |
PeruAPIs: Access Peruvian Data via Public APIs and Curated Datasets
Description
This package provides functions to access data from public RESTful APIs including 'Nager.Date', 'World Bank API', and 'REST Countries API', retrieving real-time or historical data related to Peru, such as holidays, economic indicators, and international demographic and geopolitical indicators. Additionally, the package includes curated datasets focused on Peru, covering topics such as administrative divisions, electoral data, demographics, biodiversity and educational classifications.
Details
PeruAPIs: Access Peruvian Data via Public APIs and Curated Datasets
Access Peruvian Data via Public APIs and Curated Datasets.
Author(s)
Maintainer: Renzo Caceres Rossi arenzocaceresrossi@gmail.com
See Also
Useful links:
Peruvian Andean migrants health study
Description
This dataset, andean_migrants_health_df, is a data frame containing health data from a random sample of Peruvians born in the Andes mountains, but who have since migrated to lower altitudes. The sample was collected to assess the long-term effects of altitude on blood pressure and other health indicators, providing valuable insights into the physiological adaptations of high-altitude populations.
Usage
data(andean_migrants_health_df)
Format
A data frame with 39 observations and 5 variables:
- age
Age of the subject (integer)
- years
Years since migration to lower altitude (integer)
- weight
Weight of the subject (numeric)
- height
Height of the subject (integer)
- BP
Blood pressure measurement (integer)
Details
The dataset name has been kept as 'andean_migrants_health_df' to avoid confusion with other datasets in the R ecosystem. This naming convention helps distinguish this dataset as part of the PeruAPIs package and assists users in identifying its specific characteristics. The suffix 'df' indicates that the dataset is a data frame object. The original content has not been modified in any way.
Source
Data taken from the s20x package version 3.1-40
Bird species recorded in Peru
Description
This dataset, birds_peru_tbl_df, is a tibble containing an updated list of bird species recorded in Peru, based on the most recent taxonomic revisions by the South American Checklist Committee (SACC). It provides comprehensive information about avian biodiversity in Peru, including taxonomic classification, common names in English and Spanish, and conservation status for each species.
Usage
data(birds_peru_tbl_df)
Format
A tibble with 1,914 observations and 6 variables:
- order_name
Taxonomic order of the bird species (character)
- family_name
Taxonomic family of the bird species (character)
- scientific_name
Scientific name of the bird species (character)
- english_name
Common name in English (character)
- spanish_name
Common name in Spanish (character)
- status
Conservation or taxonomic status of the species (character)
Details
The dataset name has been kept as 'birds_peru_tbl_df' to avoid confusion with other datasets in the R ecosystem. This naming convention helps distinguish this dataset as part of the PeruAPIs package and assists users in identifying its specific characteristics. The suffix 'tbl_df' indicates that the dataset is a tibble object. The original content has not been modified in any way.
Source
Data taken from the avesperu package version 0.0.6
Get Country Information for Peru
Description
Retrieves comprehensive country information for Peru from the REST Countries API. This function fetches data including official and common names, geographical information, capital, area, population, and languages.
Usage
get_country_info_pe()
Details
This function makes a request to the REST Countries API v3.1 endpoint specifically for Peru using full text search. It handles API errors gracefully and returns NULL if the request fails or no data is found.
Value
A tibble with one row containing Peru's country information:
- name_common
Common name of the country
- name_official
Official name of the country
- region
Geographic region
- subregion
Geographic subregion
- capital
Capital city(ies)
- area
Total area in square kilometers
- population
Total population
- languages
Languages spoken (comma-separated)
Examples
# Get Peru information
pe_info <- get_country_info_pe()
print(pe_info)
Get Peru's Under-5 Mortality Rate from World Bank
Description
Retrieves Peru's under-5 mortality rate, measured as the number of deaths
of children under five years of age per 1,000 live births, for the years 2010 to 2022
using the World Bank Open Data API. The indicator used is SH.DYN.MORT
.
Usage
get_peru_child_mortality()
Details
This 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., "Mortality rate, under-5 (per 1,000 live births)") -
country
: Country name ("Peru") -
year
: Year of the data (integer) -
value
: Mortality rate (per 1,000 live births)
Note
Requires internet connection.
Source
World Bank Open Data API: https://data.worldbank.org/indicator/SH.DYN.MORT
See Also
Examples
if (interactive()) {
get_peru_child_mortality()
}
Get Peru's Consumer Price Index (2010 = 100) from World Bank
Description
Retrieves Peru's Consumer Price Index (CPI), with 2010 as the base year (index = 100),
for the years 2010 to 2022 using the World Bank Open Data API.
The indicator used is FP.CPI.TOTL
.
Usage
get_peru_cpi()
Details
This 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., "Consumer price index (2010 = 100)") -
country
: Country name ("Peru") -
year
: Year of the data (integer) -
value
: Consumer Price Index (numeric, base year 2010 = 100)
Note
Requires internet connection.
Source
World Bank Open Data API: https://data.worldbank.org/indicator/FP.CPI.TOTL
See Also
Examples
if (interactive()) {
get_peru_cpi()
}
Get Peru's Energy Use (kg of oil equivalent per capita) from World Bank
Description
Retrieves Peru's energy use per capita, measured in kilograms of oil equivalent,
for the years 2010 to 2022 using the World Bank Open Data API.
The indicator used is EG.USE.PCAP.KG.OE
.
Usage
get_peru_energy_use()
Details
This 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., "Energy use (kg of oil equivalent per capita)") -
country
: Country name ("Peru") -
year
: Year of the data (integer) -
value
: Energy use in kilograms of oil equivalent per capita
Note
Requires internet connection.
Source
World Bank Open Data API: https://data.worldbank.org/indicator/EG.USE.PCAP.KG.OE
See Also
Examples
if (interactive()) {
get_peru_energy_use()
}
Get Peru's GDP (current US$) from World Bank
Description
Retrieves Peru'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_peru_gdp()
Details
This 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 ("Peru") -
year
: Year of the data (integer) -
value
: GDP in current US dollars -
value_label
: Formatted GDP with commas (e.g., "1,800,000,000,000")
Note
Requires internet connection.
Source
World Bank Open Data API: https://data.worldbank.org/indicator/NY.GDP.MKTP.CD
See Also
GET
, fromJSON
, as_tibble
, comma
Examples
if (interactive()) {
get_peru_gdp()
}
Get Official Public Holidays in Peru for a Given Year
Description
Retrieves the list of official public holidays in Peru for a specific year using the Nager.Date public holidays API. This function returns a tibble containing the date of the holiday, the name in the local language (Spanish), and the English name. It is useful for academic, planning, and data analysis purposes. The information is retrieved directly from the Nager.Date API and reflects the current status of holidays for the requested year. The field names returned are consistent with the API structure.
Usage
get_peru_holidays(year)
Arguments
year |
An integer indicating the year (e.g., 2024 or 2025). |
Value
A tibble with the following columns:
-
date
: Date of the holiday (classDate
) -
local_name
: Holiday name in the local language (Spanish) -
name
: Holiday name in English
Source
Data obtained from the Nager.Date API: https://date.nager.at/
Examples
get_peru_holidays(2024)
get_peru_holidays(2025)
Get Peru's Hospital Beds (per 1,000 people) from World Bank
Description
Retrieves Peru's number of hospital beds per 1,000 people
for the years 2010 to 2022 using the World Bank Open Data API.
The indicator used is SH.MED.BEDS.ZS
.
Usage
get_peru_hospital_beds()
Details
This 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., "Hospital beds (per 1,000 people)") -
country
: Country name ("Peru") -
year
: Year of the data (integer) -
value
: Number of hospital beds per 1,000 people
Note
Requires internet connection.
Source
World Bank Open Data API: https://data.worldbank.org/indicator/SH.MED.BEDS.ZS
See Also
Examples
if (interactive()) {
get_peru_hospital_beds()
}
Get Peru's Life Expectancy at Birth (Total, Years) from World Bank
Description
Retrieves Peru's life expectancy at birth (total, years)
for the years 2010 to 2022 using the World Bank Open Data API.
The indicator used is SP.DYN.LE00.IN
.
Usage
get_peru_life_expectancy()
Details
This 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., "Life expectancy at birth, total (years)") -
country
: Country name ("Peru") -
year
: Year of the data (integer) -
value
: Life expectancy at birth in years
Note
Requires internet connection.
Source
World Bank Open Data API: https://data.worldbank.org/indicator/SP.DYN.LE00.IN
See Also
Examples
if (interactive()) {
get_peru_life_expectancy()
}
Get Peru's Adult Literacy Rate
Description
Retrieves Peru's adult literacy rate (
for the years 2010 to 2022 using the World Bank Open Data API.
The indicator used is SE.ADT.LITR.ZS
.
Usage
get_peru_literacy_rate()
Details
This 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 -
country
: Country name ("Peru") -
year
: Year of the data (integer) -
value
: Literacy rate as a percentage
Note
Requires internet connection.
Source
World Bank Open Data API: https://data.worldbank.org/indicator/SE.ADT.LITR.ZS
See Also
Examples
literacy_data <- get_peru_literacy_rate()
head(literacy_data)
Get Peru's Total Population from World Bank
Description
Retrieves Peru'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_peru_population()
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., "Population, total") -
country
: Country name ("Peru") -
year
: Year of the data (integer) -
value
: Population as a numeric value -
value_label
: Formatted population with commas (e.g., "51,000,000")
Note
Requires internet connection. The data is retrieved in real time from the World Bank API.
Source
World Bank Open Data API: https://data.worldbank.org/indicator/SP.POP.TOTL
See Also
GET
, fromJSON
, as_tibble
, comma
Examples
if (interactive()) {
get_peru_population()
}
Get Peru's Unemployment Rate (Total) from World Bank
Description
Retrieves Peru's total unemployment rate, measured as a percentage of the total labor force,
for the years 2010 to 2022 using the World Bank Open Data API.
The indicator used is SL.UEM.TOTL.ZS
.
Usage
get_peru_unemployment()
Details
This 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., "Unemployment, total ( -
country
: Country name ("Peru") -
year
: Year of the data (integer) -
value
: Unemployment rate as a numeric value (percentage)
Note
Requires internet connection.
Source
World Bank Open Data API: https://data.worldbank.org/indicator/SL.UEM.TOTL.ZS
See Also
Examples
if (interactive()) {
get_peru_unemployment()
}
Peru's educational programs under ISCED classification
Description
This dataset, iscd_education_tbl_df, is a tibble containing Peru's educational programs classified according to the International Standard Classification of Education (ISCED). It provides comprehensive information about educational codes, classifications, academic levels, and program specifications used in Peru's educational system, facilitating standardized comparison and analysis of educational data.
Usage
data(iscd_education_tbl_df)
Format
A tibble with 8,357 observations and 8 variables:
- Education_COD
Education classification code (character)
- Education
Education category description (character)
- Specific_COD
Specific classification code (character)
- Specific
Specific category description (character)
- AcademicLevel
Academic level description (character)
- AcademicLevel_COD
Academic level code (character)
- EducationProgram
Education program name (character)
- EducationProgram_Lemma
Education program lemmatized form (character)
Details
The dataset name has been kept as 'iscd_education_tbl_df' to avoid confusion with other datasets in the R ecosystem. This naming convention helps distinguish this dataset as part of the PeruAPIs package and assists users in identifying its specific characteristics. The suffix 'tbl_df' indicates that the dataset is a tibble object. The original content has not been modified in any way.
Source
Data taken from the CINE package version 0.1.3
Peru blank votes
Description
This dataset, peru_blank_votes_df, is a data frame containing data on the blank votes in the 2006 Peruvian general election. It provides information about voting patterns and their relationship with the Human Development Index (HDI), offering insights into electoral behavior and socioeconomic factors in Peru's democratic process.
Usage
data(peru_blank_votes_df)
Format
A data frame with 194 observations and 2 variables:
- votes
Number of blank votes (numeric)
- HDI
Human Development Index (numeric)
Details
The dataset name has been kept as 'peru_blank_votes_df' to avoid confusion with other datasets in the R ecosystem. This naming convention helps distinguish this dataset as part of the PeruAPIs package and assists users in identifying its specific characteristics. The suffix 'df' indicates that the dataset is a data frame object. The original content has not been modified in any way.
Source
Data taken from the PLreg package version 0.4.1
Peruvian coastline coordinates
Description
This dataset, peru_coastline_df, is a data frame containing the coastline of Peru represented as a spatial object. It provides geographical coordinates that define the outline of Peru's Pacific coast, which can be used for mapping, spatial analysis, and visualization purposes.
Usage
data(peru_coastline_df)
Format
A data frame with 23,481 observations and 2 variables:
- Long
Longitude coordinates of coastline points (numeric)
- Lat
Latitude coordinates of coastline points (numeric)
Details
The dataset name has been kept as 'peru_coastline_df' to avoid confusion with other datasets in the R ecosystem. This naming convention helps distinguish this dataset as part of the PeruAPIs package and assists users in identifying its specific characteristics. The suffix 'df' indicates that the dataset is a data frame object. The original content has not been modified in any way.
Source
Data taken from the Tivy package version 0.1.1
View Available Datasets in PeruAPIs
Description
This function lists all datasets available in the 'PeruAPIs' package. If the 'PeruAPIs' 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_PeruAPIs()
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("PeruAPIs", quietly = TRUE)) {
library(PeruAPIs)
view_datasets_PeruAPIs()
}