Add or update a file in a dataset. For most applications, this
is the recommended function to upload your own local datasets to an
existing Dataverse dataset. Uploading requires a Dataverse API Key in the key
variable.
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"),
...
)
A character string for the location path of the file to be uploaded.
A character specifying a persistent identification ID for a dataset,
for example "10.70122/FK2/HXJVJU"
. Alternatively, an object of class
“dataverse_dataset” obtained by dataverse_contents()
.
Optionally, a character string providing a description of the file.
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")
.
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
. See use_cache
for details
on how the R dataverse package uses disk and session caches to
improve network performance.
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
.
A logical indicating whether to force the update even if the file
types differ. Default is TRUE
.
add_dataset_file
returns the new file ID. It also uploads the file
to the dataset.
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
).
if (FALSE) { # \dontrun{
meta <- list()
ds <- create_dataset("mydataverse", body = meta)
# Upload RDS dataset saved to local
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)
} # }