add_dataset_file {dataverse}R Documentation

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

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

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. Multiple Dataverse installations exist, with "dataverse.harvard.edu" being the most major. The server can be defined each time within a function, or it can be set as a default via an environment variable. To set a default, run Sys.setenv("DATAVERSE_SERVER" = "dataverse.harvard.edu") or add ⁠DATAVERSE_SERVER = "dataverse.harvard.edu⁠ in one's .Renviron file (usethis::edit_r_environ()), with the appropriate domain as its value.

...

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.

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

Value

add_dataset_file returns the new file ID.

See Also

get_dataset, delete_dataset, publish_dataset

Examples

## 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)

## End(Not run)

[Package dataverse version 0.3.10 Index]