| Type: | Package |
| Title: | Client for the 'MoSPI' Microdata Portal |
| Version: | 0.1.0 |
| 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. |
| License: | MIT + file LICENSE |
| Encoding: | UTF-8 |
| Language: | en-US |
| Depends: | R (≥ 4.1.0) |
| Imports: | httr2 (≥ 1.0.0) |
| Suggests: | testthat (≥ 3.0.0), knitr, rmarkdown |
| VignetteBuilder: | knitr |
| Config/testthat/edition: | 3 |
| Config/Needs/website: | pkgdown |
| URL: | https://mospir.saketlab.org, https://github.com/saketkc/mospiR |
| BugReports: | https://github.com/saketkc/mospiR/issues |
| Config/roxygen2/version: | 8.1.0 |
| NeedsCompilation: | no |
| Packaged: | 2026-10-16 21:20:25 UTC; mcclintock |
| Author: | Saket Choudhary |
| Maintainer: | Saket Choudhary <saketc@iitb.ac.in> |
| Repository: | CRAN |
| Date/Publication: | 2026-10-27 17:10:02 UTC |
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"))