mospiR mospiR logo

mospiR is an R client for the MoSPI Microdata Portal. The package downloads unit-level survey data from the Ministry of Statistics and Programme Implementation (MoSPI) of India.

Installation

# CRAN
install.packages("mospiR")

# Development version
remotes::install_github("saketkc/mospiR")

Setup

  1. Get an API key from microdata.gov.in.
  2. Add the key to ~/.Renviron:
MOSPI_KEY=your-key-here
api_key <- Sys.getenv("MOSPI_KEY")

Usage

Search datasets

library(mospiR)

# All datasets (all pages)
all <- list_datasets(api_key)

# Datasets with "labour force" in the title
labour <- list_datasets(api_key, query = "labour force")

# Only page 1
page1 <- list_datasets(api_key, page = 1)

List files in a dataset

files <- list_files("DDI-IND-MOSPI-NSSO-68Rnd-Sch2.0-July2011-June2012", api_key)
files[, c("name", "size")]

Download a single file

download_file(
  dataset_id  = "DDI-IND-MOSPI-NSSO-68Rnd-Sch2.0-July2011-June2012",
  file_name   = "Nss68_1.0_Type2_new format.rar",
  folder_path = "data/nss68",
  api_key     = api_key
)

Download all files in a dataset

download_dataset(
  dataset_id  = "DDI-IND-MOSPI-NSSO-68Rnd-Sch2.0-July2011-June2012",
  folder_path = "data/nss68",
  api_key     = api_key
)