Learn R Programming

dataverse (version 0.2.0)

add_dataset_file: Add or update a file in a dataset

Description

Add or update a file in a dataset

Usage

add_dataset_file(file, dataset, description = NULL,
  key = Sys.getenv("DATAVERSE_KEY"),
  server = Sys.getenv("DATAVERSE_SERVER"), ...)

update_dataset_file(file, dataset = NULL, id, description = NULL, force = TRUE, key = Sys.getenv("DATAVERSE_KEY"), server = Sys.getenv("DATAVERSE_SERVER"), ...)

Arguments

file

A character string

dataset

An integer specifying a dataset identification number or an object of class “dataverse_dataset”. The identification number is the dataset's persistent identification number (not the integer specifying a specific version of the dataset, such as returned by dataset_versions).

description

Optionally, a character string providing a description of the file.

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. 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.

id

An integer specifying a file identifier; or, if doi is specified, a character string specifying a file name within the DOI-identified dataset; or an object of class “dataverse_file” as returned by dataset_files.

force

A logical indicating whether to force the update even if the file types differ. Default is TRUE.

Value

add_dataset_file returns the new file ID.

Details

From Dataverse v4.6.1, the “native” API provides endpoints to add and update files without going through the SWORD workflow. To use SWORD instead, see add_file. add_dataset_file adds a new file to a specified dataset.

update_dataset_file can be used to replace/update a published file. Note that it only works on published files, so unpublished drafts cannot be updated - the dataset must first either be published (publish_dataset) or deleted (delete_dataset).

See Also

get_dataset, delete_dataset, publish_dataset

Examples

Run this code
# NOT RUN {
meta <- list()
ds <- create_dataset("mydataverse", body = meta)

saveRDS(mtcars, tmp <- tempfile(fileext = ".rds"))
f <- add_dataset_file(tmp, dataset = ds, description = "mtcars")

# publish dataset
publish_dataset(ds)

# update file and republish
saveRDS(iris, tmp)
update_dataset_file(tmp, dataset = ds, id = f, 
                    description = "Actually iris")
publish_dataset(ds)

# cleanup
unlink(tmp)
delete_dataset(ds)
# }

Run the code above in your browser using DataLab