add_dataset_file {dataverse} | R Documentation |
Add or update a file in a dataset
Description
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.
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 for the location path of the file to be uploaded. |
dataset |
A character specifying a persistent identification ID for a dataset,
for example |
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
|
server |
A character string specifying a Dataverse server.
Multiple Dataverse installations exist, with |
... |
Additional arguments passed to an HTTP request function, such as
|
id |
An integer specifying a file identifier; or, if |
force |
A logical indicating whether to force the update even if the file
types differ. Default is |
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. It also uploads the file
to the dataset.
See Also
get_dataset
, delete_dataset
, publish_dataset
Examples
## Not run:
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)
## End(Not run)