2. Data Search and Discovery

options(width = 120)
knitr::opts_chunk$set(results = "hold")

Searching for data within Dataverse is quite easy using the dataverse_search() function. The simplest searches simply consist of a query string:

library("dataverse")
Sys.setenv("DATAVERSE_SERVER" = "dataverse.harvard.edu")
dataverse_search("Gary King")[c("name")]

The results are paginated, so users can rely upon the per_page and start argument to requested subsequent pages of results. We'll start at 6 and to show that we retrieve the last five results from the previous query plus 15 more (due to per_page = 20):

dataverse_search("Gary King", start = 6, per_page = 20)[c("name")]

More complicated searches can specify metadata fields like title and restrict results to a specific type of Dataverse object (a "dataverse", "dataset", or "file"):

ei <- dataverse_search(author = "Gary King", title = "Ecological Inference", type = "dataset", per_page = 20)
# fields returned
names(ei)
# names of datasets
ei$name

Once datasets and files are identified, it is easy to download and use them directly in R. See the "Data Download" vignette for details.



Try the dataverse package in your browser

Any scripts or data that you put into this service are public.

dataverse documentation built on March 31, 2023, 7:26 p.m.