Learn R Programming

ChinAPIs

The ChinAPIs package provides a unified interface to access open data from the World Bank API, Nager.Date API, and the REST Countries API, with a focus on China. It allows users to retrieve up-to-date information on topics such as economic indicators, population statistics, unemployment rates, holidays, and basic geopolitical details.

In addition to API-access functions, the package includes one of the largest curated collections of open datasets related to China and Hong Kong. These datasets cover areas such as air quality, demographic indicators, input-output economic tables, epidemiology, administrative divisions, name distributions, political structure, and various social indicators.

Installation

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


install.packages("ChinAPIs")

Usage

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


library(ChinAPIs)

ChinAPIs Functions

Below is a list of the main functions included in the package:

  • get_country_info_cn(): Get key geopolitical and administrative information about China from the REST Countries API.

  • get_china_gdp(): Get China’s Gross Domestic Product (current US$) from the World Bank

  • get_china_cpi(): Get China's Consumer Price Index from World Bank

  • get_china_population(): Get China’s total population from the World Bank

  • get_china_literacy_rate(): Get China's adult literacy rate (Age 15+) from the World Bank

  • get_china_life_expectancy(): Get life expectancy at birth for China from the World Bank

  • get_china_unemployment(): Get China's Unemployment Rate from World Bank

  • get_china_energy_use(): Get China's energy use per capita (kg of oil equivalent) from the World Bank

  • get_china_child_mortality(): Get under-5 mortality rate (per 1,000 live births) in China from the World Bank

  • get_china_hospital_beds(): Get hospital beds per 1,000 people in China from the World Bank

  • get_china_holidays(): Retrieve Chinese public holidays (including past and upcoming dates) from the Nager.Date API (e.g., get_china_holidays(2024), get_china_holidays(2025)).

  • view_datasets_ChinAPIs(): Lists all curated datasets included in the ChinAPIs package

Dataset Suffixes

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

  • _df: A standard data frame.

  • _tbl_df: A tibble data frame object.

  • _list: A list object.

  • _matrix: A matrix object.

Datasets Included in ChinAPIs

In addition to API access functions, ChinAPIs provides several preloaded datasets related to China’s air quality, demographics, input-output tables, epidemiology, political structure, names, and social indicators. Here are some featured examples:

  • bj_air_quality_tbl_df: Tibble of hourly air pollution and weather measurements from Dongsi, Beijing.

  • china_admin_divisions_df: Data frame containing the codes and names of China's administrative divisions.

  • shanghai_factories_df: Data frame containing data on per capita output of workers in 17 factories located in Shanghai.

Example Code:


# Load the package

library(ChinAPIs)

# Retrieves essential information about China

get_country_info_cn()

# Get China's Population (Total) from World Bank

get_china_population()

# Load a dataset

data(china_cars_tbl_df)

# Shows six rows of the dataset

head(china_cars_tbl_df)

# Display the structure of the dataset

str(china_cars_tbl_df)

# Shows the whole dataset

View(china_cars_tbl_df)

Copy Link

Version

Install

install.packages('ChinAPIs')

Monthly Downloads

168

Version

0.1.0

License

MIT + file LICENSE

Issues

Pull Requests

Stars

Forks

Maintainer

Renzo Caceres Rossi

Last Published

August 26th, 2025

Functions in ChinAPIs (0.1.0)

china_io_2002_122_df

Input-output Table for China, 2002 (122 Sectors)
COVID19_HongKong_df

COVID-19 Offspring Cases in Hong Kong (Jan–Apr 2020)
bj_air_quality_tbl_df

Beijing Air Quality Dataset (2015)
china_cars_tbl_df

Stated Car Choice Data from Chinese Buyers
ChinAPIs

ChinAPIs: Access Chinese Data via APIs and Curated Datasets
china_io_2005_42_df

Input-output Table for China, 2005 (42 Sectors)
china_io_2007_135_df

Input-output Table for China, 2007 (135 Sectors)
china_io_2010_41_df

Input-output Table for China, 2010 (41 Sectors)
china_admin_divisions_df

Administrative Divisions of China
china_corruption_tbl_df

China's Corruption Investigations
china_io_2018_153_df

China Input-Output Table (2018, 153 Sectors)
china_io_2012_139_df

Input-output Table for China, 2012 (139 Sectors)
china_io_2020_153_df

Input-output Table for China, 2020 (153 Sectors)
chinese_dams_tbl_df

Chinese Dams Dataset
china_io_2017_42_df

China Input-Output Table (2017, 42 Sectors)
china_io_2020_42_df

China Input-Output Table (2020, 42 Sectors)
china_io_2018_42_df

China Input-Output Table (2018, 42 Sectors)
china_io_2015_42_df

Input-output Table for China, 2015 (42 Sectors)
chinese_cities_tbl_df

List of Prominent Chinese Cities
china_io_2017_149_df

Input-output Table for China, 2017 (149 Sectors)
get_china_cpi

Get China's Consumer Price Index from World Bank
get_china_hospital_beds

Get Hospital Beds per 1,000 People in China from World Bank
get_china_life_expectancy

Get China's Life Expectancy at Birth from World Bank
family_name_df

Chinese Surnames and National Frequency (1930–2008)
get_china_gdp

Get China's GDP (Current US$) from World Bank
get_china_holidays

Get Official Public Holidays in China for a Given Year
get_china_energy_use

Get China's Energy Use (kg of oil equivalent per capita) from World Bank
hk_population_tbl_df

Hong Kong Population by District and Age Group
get_china_unemployment

Get China's Unemployment Rate from World Bank
get_china_child_mortality

Get Under-5 Mortality Rate in China from World Bank
get_china_population

Get China's Total Population from World Bank
get_china_literacy_rate

Get China's Literacy Rate (Age 15+) from World Bank
hk_street_names_tbl_df

Hong Kong Street Names as of 2020
given_name_df

Chinese Given Name Characters and Frequency (1930–2008)
hk_councillors_tbl_df

Hong Kong District Councillors Elected in 2019
panda_locations_df

Giant Panda Location Data
population_df

Population Statistics from the Chinese Name Database
wenchuan_ptsd_matrix

PTSD Symptoms of Wenchuan Earthquake Survivors
shanghai_pm25_df

PM2.5 Pollution and Weather Data in Shanghai
get_country_info_cn

Get Key Country Information About China from the REST Countries API
sars_hong_kong_list

Daily Incidence of the 2003 SARS Epidemic in Hong Kong
top50char_year_df

Top 50 Given-Name Characters in 6 Birth Cohorts
hk_districts_tbl_df

Hong Kong District Labels and Regional Classification
shanghai_factories_df

Per Capita Output of Workers in Shanghai Factories
top1000name_prov_df

Top 1,000 Given Names by Province in Mainland China
health_family_life_df

Chinese Health and Family Life Survey
top100name_year_df

Top 100 Given Names in 6 Birth Cohorts
view_datasets_ChinAPIs

View Available Datasets in ChinAPIs