-
Notifications
You must be signed in to change notification settings - Fork 14
Home
Provides an Interface to Zenodo REST API, including management of depositions, attribution of DOIs by 'Zenodo' and upload of files.
If you wish to sponsor zen4R
, do not hesitate to contact me
Many thanks to the following organizations that have provided fundings for strenghtening the zen4R
package:
Table of contents
1. Overview
2. Package status
3. Credits
4. User guide
4.1 Installation
4.2 Connect to Zenodo REST API
4.3 Manage Zenodo record depositions
4.3.1 Create an empty record
4.3.2 Fill a record
4.3.3 Deposit/Update a record
4.3.4 Delete a record
4.3.5 Publish a record
4.3.6 Edit/Update a published record
4.3.7 Discard changes of a draft record
4.3.8 Create a new record version
4.4 Manage Zenodo record deposition files
4.4.1 Upload file
4.4.2 Get files
4.4.3 Delete file
5. Issue reporting
The zen4R package offers an R interface to the Zenodo e-infrastructure. It supports the creation of metadata records (including versioning), upload of files, and assignment of Digital Object Identifier(s) (DOIs).
zen4R is jointly developed together with the geoflow which intends to facilitate and automate the production of geographic metadata documents and their associated datasources, where zen4R is used to assign DOIs and cross-reference these DOIs in other metadata documents such as geographic metadata (ISO 19115/19139) hosted in metadata catalogues and open data portals.
- January 2019: Inception. Code source managed on GitHub.
- June 2019: Published on CRAN.
(c) 2019, Emmanuel Blondel
Package distributed under MIT license.
If you use zen4R
, i would be very grateful if you can add a citation in your published work. By citing zen4R
, beyond acknowledging the work, you contribute to make it more visible and guarantee its growing and sustainability. For citation, please use the DOI:
For now, the package can be installed from Github
install.packages("devtools")
Once the devtools package loaded, you can use the install_github to install zen4R
. By default, package will be installed from master
which is the current version in development (likely to be unstable).
require("devtools")
install_github("eblondel/zen4R")
The main entry point of zen4R
is the ZenodoManager
. Some basic methods, such as listing licenses known by Zenodo, do not require the token.
zenodo <- ZenodoManager$new()
To use deposit functions of zen4R
, you will need to specify the token
. This token can be created here.
zenodo <- ZenodoManager$new(
token = <your_token>,
logger = "INFO" # use "DEBUG" to see detailed API operation logs, use NULL if you don't want logs at all
)
By default, the zen4R
logger is deactivated. To enable the logger, specify the level of log you wish as parameter of the above R code. Two logging levels are available:
-
INFO
: will print thezen4R
logs. Three types of messages can be distinguished:INFO
,WARN
,ERROR
. The latter is generally associated with astop
and indicate an blocking error for the R method executed. -
DEBUG
will print the abovezen4R
logs, and report all logs from HTTP requests performed withcURL
It is possible to create and deposit an empty record, ready for editing. For that, run the following R code:
myrec <- zenodo$createEmptyRecord()
This method will return an object of class ZenodoRecord
for which an internal id
and a DOI have been pre-defined by Zenodo. An alternate method is to create a local empty record (not deposited on Zenodo) doing:
myrec <- ZenodoRecord$new()
The next section explains how to fill the record with metadata elements.
Zenodo records can be described a set of multiple metadata elements. For a full documentation of these metadata elements, please consult the zen4R documentation with ?ZenodoRecord
. The online Zenodo API documentation can be consulted as well here.
Example of record filling with metadata elements:
myrec <- ZenodoRecord$new()
myrec$setTitle("my R package")
myrec$setDescription("A description of my R package")
myrec$setUploadType("software")
myrec$addCreator(firstname = "John", lastname = "Doe", affiliation = "Independent", orcid = "0000-0000-0000-0000")
myrec$setLicense("mit")
myrec$setAccessRight("open")
myrec$setDOI("mydoi") #use this method if your DOI has been assigned elsewhere, outside Zenodo
myrec$addCommunity("ecfunded")
Once the record is edited/updated, you can deposit it on Zenodo with the following code:
myrec <- zenodo$depositRecord(myrec)
In order to apply further methods on this record (e.g. upload a file, publish/delete a record), you need to get the output of the function depositRecord
(see example above) since after the deposition Zenodo will return the record that contains now an internal id
required to identify and apply further actions. This id can be inspected with myrec$id
.
Instead, if you don't get the output of depositRecord
and try to upload files or publish/delet the record based on the local record you handle (built upon ZenodoRecord$new()
), this wil not work. Because it is a local record, the id
of the record will still be NULL
, with no value assigned by Zenodo, and Zenodo will be unable to identify which record needs to be handled.
A record deposited on Zenodo but not yet published remains in the Upload area of Zenodo (a kind of staging area where draft records are in edition). As long as it is not published, a record can be deleted from the Zenodo Upload area using:
zenodo$deleteRecord(myrec$id)
To publish a deposited record and make it available publicly online on Zenodo, the following method can be run:
myrec <- zenodo$publishRecord(myrec$id)
A shortcut to publish a record is also available through the method depositRecord
, specifying publish = TRUE
. This method should be used with cautious giving the fact the record will go straight online on Zenodo if published. By default the parameter publish
will be set to FALSE
:
myrec <- zenodo$depositRecord(myrec, publish = TRUE)
The publication of a record requires at least to have uploaded at least one file for this record. See section 4.4.1 Upload file.
It is possible to update metadata of a published record, but not to modify the files associated to it. In order to update metadata of a published record, the state
of this record has to be modified to make it editable. For that, use the editRecord
function giving the id
of the record to edit:
myrec <- zenodo$editRecord(myrec$id)
Next, perform your metadata updates, and re-deposit the record
myrec$setTitle("newtitle")
myrec <- zenodo$depositRecord(myrec, publish = FALSE)
Since the record has been switched back to draft
state, the record has to be re-published otherwise it will remain a draft record in your Zenodo user session.
In case you started editing a record and you want to discard changes on it, it is possible to do it with the discardChanges
.
zenodo$discardChanges(myrec$id)
To create a new record version, you should first retrieve the record for which you want to create a new version. You can retrieve this record with methods based on DOI such as getDepositionByConceptDOI
(to get a record based on concept DOI) or getDepositionByDOI
; or by Zenodo id
with getDepositionById
:
#get record by DOI
myrec <- zenodo$getDepositionByDOI("<some doi>")
#edit myrec with updated metadata for the new version
#...
#create new version
myrec <- zenodo$depositRecordVersion(myrec, delete_latest_files = TRUE, files = "newversion.csv", publish = FALSE)
The functio depositRecordVersion
will create a new version for the published record. The parameter delete_latest_files
(default = TRUE
) allows to delete latest files (knowing that a new record version expect to have different file(s) than the latest version). The files
parameter allows to list the files to be uploaded. As for the depositRecord
, it is possible to publish the record with the publish
paramater.
With zen4R
, it is very easy to upload a file to a record deposition. The record should first deposited on Zenodo. To upload a file, the following single line can be used, where the file path
is specified and the record deposition id
to which the file should be uploaded:
zenodo$uploadFile("path/to/your/file", myrec$id)
To get the list of files attached to a record, you can specify the following method adding the record id
:
zen_files <- zenodo$getFiles(myrec$id)
This retrieves a list of files. Each file has a unique id
, that can be used to for file deletion.
The following example shows how to delete the first file attached to the record defined earlier. To delete a file, we need to specify both the record and file identifiers:
zenodo$deleteFile(myrec$id, zen_files[[1]]$id)
Issues can be reported at https://github.com/eblondel/zen4R/issues