| 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 |
Download all files for a dataset
download_dataset(dataset_id, folder_path, api_key, overwrite = FALSE)download_dataset(dataset_id, folder_path, api_key, overwrite = FALSE)
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'. |
A character vector of the paths of the saved files, as an invisible value.
# This dataset is approximately 270 MB. paths <- download_dataset( "DDI-IND-NSO-ASI-2020-21", tempdir(), Sys.getenv("MOSPI_KEY") )# 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
download_file(dataset_id, file_name, folder_path, api_key, .files_cache = NULL)download_file(dataset_id, file_name, folder_path, api_key, .files_cache = NULL)
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. |
The path of the saved file, as an invisible value. 'NULL' if the download is not successful.
path <- download_file( "DDI-IND-NSO-ASI-2020-21", "DDI-IND-NSO-ASI-2020-21.xml", tempdir(), Sys.getenv("MOSPI_KEY") )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
list_datasets(api_key, page = NULL, query = NULL)list_datasets(api_key, page = NULL, query = NULL)
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. |
A data frame with the columns 'id', 'idno', 'title', and other columns. 'NULL' if the request is not successful.
page1 <- list_datasets(Sys.getenv("MOSPI_KEY"), page = 1) head(page1[, c("idno", "title")])page1 <- list_datasets(Sys.getenv("MOSPI_KEY"), page = 1) head(page1[, c("idno", "title")])
List files available for a dataset
list_files(dataset_id, api_key)list_files(dataset_id, api_key)
dataset_id |
Dataset 'idno', for example '"DDI-IND-NSO-ASI-2020-21"'. |
api_key |
MoSPI API key. |
A data frame with the columns 'name', 'base64', 'size', and other columns. 'NULL' if the request is not successful.
files <- list_files("DDI-IND-NSO-ASI-2020-21", Sys.getenv("MOSPI_KEY"))files <- list_files("DDI-IND-NSO-ASI-2020-21", Sys.getenv("MOSPI_KEY"))