Skip to contents

License: MIT

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.

ChinAPIs Functions

Below is a list of the main functions included in the 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)