Learn R Programming

dataverse (version 0.3.0)

get_dataset: Get dataset

Description

Retrieve a Dataverse dataset or its metadata

Usage

get_dataset(
  dataset,
  version = ":latest",
  key = Sys.getenv("DATAVERSE_KEY"),
  server = Sys.getenv("DATAVERSE_SERVER"),
  ...
)

dataset_metadata( dataset, version = ":latest", block = "citation", key = Sys.getenv("DATAVERSE_KEY"), server = Sys.getenv("DATAVERSE_SERVER"), ... )

dataset_files( dataset, version = ":latest", key = Sys.getenv("DATAVERSE_KEY"), server = Sys.getenv("DATAVERSE_SERVER"), ... )

Arguments

dataset

A character specifying a persistent identification ID for a dataset, for example "doi:10.70122/FK2/HXJVJU". Alternatively, an object of class “dataverse_dataset” obtained by dataverse_contents().

version

A character string specifying a version of the dataset. This can be one of “:draft” (the current draft), “:latest” (the latest draft, if it exists, or the latest published version), “:latest-published” (the latest published version, ignoring any draft), or “x.y” (where x is a major version and y is a minor version; the .y can be omitted to obtain a major version). In lieu of this, a dataset's version-specific identification number can be used for the dataset argument.

key

A character string specifying a Dataverse server API key. If one is not specified, functions calling authenticated API endpoints will fail. Keys can be specified atomically or globally using Sys.setenv("DATAVERSE_KEY" = "examplekey").

server

A character string specifying a Dataverse server. There are multiple Dataverse installations, but the defaults is to use the Harvard Dataverse (server = "dataverse.harvard.edu"). This can be modified atomically or globally using Sys.setenv("DATAVERSE_SERVER" = "dataverse.example.com").

...

Additional arguments passed to an HTTP request function, such as GET, POST, or DELETE.

block

A character string specifying a metadata block to retrieve. By default this is “citation”. Other values may be available, depending on the dataset, such as “geospatial” or “socialscience”.

Value

A list of class “dataverse_dataset” or a list of a form dependent on the specific metadata block retrieved. dataset_files returns a list of objects of class “dataverse_file”.

Details

get_dataset retrieves details about a Dataverse dataset.

dataset_metadata returns a named metadata block for a dataset. This is already returned by get_dataset, but this function allows you to retrieve just a specific block of metadata, such as citation information.

dataset_files returns a list of files in a dataset, similar to get_dataset. The difference is that this returns only a list of “dataverse_dataset” objects, whereas get_dataset returns metadata and a data.frame of files (rather than a list of file objects).

See Also

create_dataset, update_dataset, delete_dataset, publish_dataset, dataset_files, dataset_metadata

Examples

Run this code
# NOT RUN {
Sys.setenv("DATAVERSE_SERVER" = "demo.dataverse.org")
Sys.setenv("DATAVERSE_KEY"    = "c7208dd2-6ec5-469a-bec5-f57e164888d4")

# Download file from: https://demo.dataverse.org/file.xhtml?fileId=769385
dv       <- get_dataverse("dataverse-client-r")
contents <- dataverse_contents(dv)

dataset_files(contents[[1]])            # Dataset contains 2 files
dataset_metadata(contents[[1]])         # Easier to query later

set      <- get_dataset(contents[[1]])  # 1st dataset w/n dataverse
f        <- get_file(set$files$id[2])   # 2nd file w/n dataset

# Check the *binary* representation of the file.
length(f)
head(f)

# Examine the plain-text representation.
tmp <- tempfile(fileext = "svg")
writeBin(as.vector(f), tmp)
svg_lines <- readLines(tmp)
head(svg_lines)
# }

Run the code above in your browser using DataLab