Package 'mospiR'

Title: Client for the 'MoSPI' Microdata Portal
Description: Download unit-level survey microdata from the Ministry of Statistics and Programme Implementation ('MoSPI', Government of India) Microdata Portal <https://microdata.gov.in>. Provides functions to list datasets, list files within a dataset, and download individual files or entire datasets through the portal's 'NADA' API.
Authors: Saket Choudhary [aut, cre] (ORCID: <https://orcid.org/0000-0001-5202-7633>)
Maintainer: Saket Choudhary <[email protected]>
License: MIT + file LICENSE
Version: 0.1.0
Built: 2026-10-27 20:29:11 UTC
Source: https://github.com/cran/mospiR

Help Index


Download all files for a dataset

Description

Download all files for a dataset

Usage

download_dataset(dataset_id, folder_path, api_key, overwrite = FALSE)

Arguments

dataset_id

Dataset 'idno'.

folder_path

Destination directory. The function makes the directory if it does not exist.

api_key

MoSPI API key.

overwrite

If 'FALSE' (default), the function does not download the files that are already in 'folder_path'.

Value

A character vector of the paths of the saved files, as an invisible value.

Examples

# This dataset is approximately 270 MB.
paths <- download_dataset(
  "DDI-IND-NSO-ASI-2020-21", tempdir(), Sys.getenv("MOSPI_KEY")
)

Download a single file from a dataset

Description

Download a single file from a dataset

Usage

download_file(dataset_id, file_name, folder_path, api_key, .files_cache = NULL)

Arguments

dataset_id

Dataset 'idno'.

file_name

File name from the 'name' column of [list_files()].

folder_path

Destination directory. The function makes the directory if it does not exist.

api_key

MoSPI API key.

.files_cache

A file list from [list_files()]. If 'NULL' (default), the function gets the file list from the portal. Use this argument when you download many files from one dataset. This prevents more API requests.

Value

The path of the saved file, as an invisible value. 'NULL' if the download is not successful.

Examples

path <- download_file(
  "DDI-IND-NSO-ASI-2020-21", "DDI-IND-NSO-ASI-2020-21.xml",
  tempdir(), Sys.getenv("MOSPI_KEY")
)

List datasets from the MoSPI Microdata Portal

Description

List datasets from the MoSPI Microdata Portal

Usage

list_datasets(api_key, page = NULL, query = NULL)

Arguments

api_key

MoSPI API key.

page

Page number to get. If 'NULL' (default), the function gets all the pages.

query

Text to find in the dataset titles. Upper case and lower case letters are equal. The comparison occurs on your computer.

Value

A data frame with the columns 'id', 'idno', 'title', and other columns. 'NULL' if the request is not successful.

Examples

page1 <- list_datasets(Sys.getenv("MOSPI_KEY"), page = 1)
head(page1[, c("idno", "title")])

List files available for a dataset

Description

List files available for a dataset

Usage

list_files(dataset_id, api_key)

Arguments

dataset_id

Dataset 'idno', for example '"DDI-IND-NSO-ASI-2020-21"'.

api_key

MoSPI API key.

Value

A data frame with the columns 'name', 'base64', 'size', and other columns. 'NULL' if the request is not successful.

Examples

files <- list_files("DDI-IND-NSO-ASI-2020-21", Sys.getenv("MOSPI_KEY"))