ZenodoManager
ZenodoManager
Object of R6Class
for modelling an ZenodoManager
R6Class
object.
Emmanuel Blondel <emmanuel.blondel1@gmail.com>
zen4R::zen4RLogger
-> ZenodoManager
sandbox
Zenodo manager sandbox status, TRUE
if we interact with Sandbox infra
anonymous
Zenodo manager anonymous status, TRUE
when no token is specified
new()
initializes the Zenodo Manager
ZenodoManager$new(
url = "https://zenodo.org/api",
token = zenodo_pat(),
sandbox = FALSE,
logger = NULL,
keyring_backend = "env"
)
url
Zenodo API URL. By default, the url is set to "https://zenodo.org/api". For tests, the Zenodo sandbox API URL can be used: https://sandbox.zenodo.org/api
token
the user token. By default an attempt will be made to retrieve token using zenodo_pat
sandbox
Indicates if the Zenodo sandbox platform should be used. Default is FALSE
logger
logger type. The logger can be either NULL, "INFO" (with minimum logs), or "DEBUG" (for complete curl http calls logs)
keyring_backend
The keyring backend used to store user token. The keyring_backend
can be set to use a different backend for storing the Zenodo token with keyring (Default value is 'env').
getToken()
Get user token
ZenodoManager$getToken()
the token, object of class character
getLicenses()
Get Licenses supported by Zenodo.
ZenodoManager$getLicenses(pretty = TRUE)
pretty
Prettify the output. By default the argument pretty
is set to
TRUE
which will returns the list of licenses as data.frame
.
Set pretty = FALSE
to get the raw list of licenses.
list of licenses as data.frame
or list
getLicenseById()
Get license by Id.
ZenodoManager$getLicenseById(id)
id
license id
the license
getCommunities()
Get Communities supported by Zenodo.
ZenodoManager$getCommunities(pretty = TRUE)
pretty
Prettify the output. By default the argument pretty
is set to
TRUE
which will returns the list of communities as data.frame
.
Set pretty = FALSE
to get the raw list of communities
list of communities as data.frame
or list
getCommunityById()
Get community by Id.
ZenodoManager$getCommunityById(id)
id
community id
the community
getGrants()
Get Grants supported by Zenodo.
ZenodoManager$getGrants(q = "", pretty = TRUE, size = 1000)
q
an ElasticSearch compliant query, object of class character
. Default is emtpy.
Note that the Zenodo API restrains a maximum number of 10,000 grants to be retrieved. Consequently,
not all grants can be listed from Zenodo, a query has to be specified.
pretty
Prettify the output. By default the argument pretty
is set to
TRUE
which will returns the list of grants as data.frame
.
Set pretty = FALSE
to get the raw list of grants
size
number of grants to be returned. By default equal to 1000.
list of grants as data.frame
or list
getGrantsByName()
Get grants by name.
ZenodoManager$getGrantsByName(name, pretty = TRUE)
name
name
pretty
Prettify the output. By default the argument pretty
is set to
TRUE
which will returns the list of grants as data.frame
.
Set pretty = FALSE
to get the raw list of grants
list of grants as data.frame
or list
getGrantById()
Get grant by Id.
ZenodoManager$getGrantById(id)
id
grant id
the grant
getFunders()
Get Funders supported by Zenodo based on a query.
ZenodoManager$getFunders(q = "", pretty = TRUE, size = 1000)
q
an ElasticSearch compliant query, object of class character
. Default is emtpy.
Note that the Zenodo API restrains a maximum number of 10,000 funders to be retrieved. Consequently,
not all funders can be listed from Zenodo, a query has to be specified.
pretty
Prettify the output. By default the argument pretty
is set to
TRUE
which will returns the list of funders as data.frame
.
Set pretty = FALSE
to get the raw list of funders
size
number of funders to be returned. By default equal to 1000.
list of funders as data.frame
or list
getFundersByName()
Get funders by name.
ZenodoManager$getFundersByName(name, pretty = TRUE)
name
name
pretty
Prettify the output. By default the argument pretty
is set to
TRUE
which will returns the list of funders as data.frame
.
Set pretty = FALSE
to get the raw list of funders
list of funders as data.frame
or list
getFunderById()
Get funder by Id.
ZenodoManager$getFunderById(id)
id
funder id
the funder
getDepositions()
Get the list of Zenodo records deposited in your Zenodo workspace. By defaut
the list of depositions will be returned by page with a size of 10 results per
page (default size of the Zenodo API). The parameter q
allows to specify
an ElasticSearch-compliant query to filter depositions (default query is empty
to retrieve all records). The argument all_versions
, if set to TRUE allows
to get all versions of records as part of the depositions list. The argument exact
specifies that an exact matching is wished, in which case paginated search will be
disabled (only the first search page will be returned).
Examples of ElasticSearch queries for Zenodo can be found at https://help.zenodo.org/guides/search/.
ZenodoManager$getDepositions(
q = "",
size = 10,
all_versions = FALSE,
exact = TRUE,
quiet = FALSE
)
q
Elastic-Search-compliant query, as object of class character
. Default is ""
size
number of depositions to be retrieved per request (paginated). Default is 10
all_versions
object of class logical
indicating if all versions of deposits have to be retrieved. Default is FALSE
exact
object of class logical
indicating if exact matching has to be applied. Default is TRUE
quiet
object of class logical
indicating if logs have to skipped. Default is FALSE
a list of ZenodoRecord
getDepositionByConceptDOI()
Get a Zenodo deposition record by concept DOI (generic DOI common to all deposition record versions).
ZenodoManager$getDepositionByConceptDOI(conceptdoi)
conceptdoi
the concept DOI, object of class character
an object of class ZenodoRecord
if record does exist, NULL otherwise
getDepositionByDOI()
Get a Zenodo deposition record by DOI.
ZenodoManager$getDepositionByDOI(doi)
doi
the DOI, object of class character
an object of class ZenodoRecord
if record does exist, NULL otherwise
getDepositionById()
Get a Zenodo deposition record by ID.
ZenodoManager$getDepositionById(recid)
recid
the record ID, object of class character
an object of class ZenodoRecord
if record does exist, NULL otherwise
getDepositionByConceptId()
Get a Zenodo deposition record by concept ID.
ZenodoManager$getDepositionByConceptId(conceptrecid)
conceptrecid
the record concept ID, object of class character
an object of class ZenodoRecord
if record does exist, NULL otherwise
depositRecord()
Deposits a record on Zenodo.
ZenodoManager$depositRecord(record, publish = FALSE)
record
the record to deposit, object of class ZenodoRecord
publish
object of class logical
indicating if record has to be published (default FALSE
).
Can be set to TRUE
(to use CAUTIOUSLY, only if you want to publish your record)
TRUE
if deposited (and eventually published), FALSE
otherwise
depositRecordVersion()
Deposits a record version on Zenodo. For details about the behavior of this function, see https://developers.zenodo.org/#new-version
ZenodoManager$depositRecordVersion(
record,
delete_latest_files = TRUE,
files = list(),
publish = FALSE
)
record
the record version to deposit, object of class ZenodoRecord
delete_latest_files
object of class logical
indicating if latest files have to be deleted. Default is TRUE
files
a list of files to be uploaded with the new record version
publish
object of class logical
indicating if record has to be published (default FALSE
)
TRUE
if deposited (and eventually published), FALSE
otherwise
deleteRecord()
Deletes a record given its ID
ZenodoManager$deleteRecord(recordId)
recordId
the ID of the record to be deleted
TRUE
if deleted, FALSE
otherwise
deleteRecordByDOI()
Deletes a record by DOI
ZenodoManager$deleteRecordByDOI(doi)
doi
the DOI of the record to be deleted
TRUE
if deleted, FALSE
otherwise
deleteRecords()
Deletes all Zenodo deposited (unpublished) records.
The parameter q
allows to specify an ElasticSearch-compliant query to filter depositions (default query
is empty to retrieve all records). Examples of ElasticSearch queries for Zenodo can be found at
https://help.zenodo.org/guides/search/.
ZenodoManager$deleteRecords(q = "", size = 10)
q
an ElasticSearch compliant query, object of class character
size
number of records to be passed to $getDepositions
method
TRUE
if all records have been deleted, FALSE
otherwise
createEmptyRecord()
Creates an empty record in the Zenodo deposit. Returns the record
newly created in Zenodo, as an object of class ZenodoRecord
with an
assigned identifier.
ZenodoManager$createEmptyRecord()
an object of class ZenodoRecord
editRecord()
Unlocks a record already submitted. Required to edit metadata of a Zenodo record already published.
ZenodoManager$editRecord(recordId)
recordId
the ID of the record to unlock and set in editing mode.
an object of class ZenodoRecord
discardChanges()
Discards changes on a Zenodo record.
ZenodoManager$discardChanges(recordId)
recordId
the ID of the record for which changes have to be discarded.
an object of class ZenodoRecord
publishRecord()
Publishes a Zenodo record.
ZenodoManager$publishRecord(recordId)
recordId
the ID of the record to be published.
an object of class ZenodoRecord
getFiles()
Get list of files attached to a Zenodo record.
ZenodoManager$getFiles(recordId)
recordId
the ID of the record.
list of files
uploadFile()
Uploads a file to a Zenodo record
ZenodoManager$uploadFile(path, record = NULL, recordId = NULL)
path
Local path of the file
record
object of class ZenodoRecord
recordId
ID of the record. Deprecated, use record
instead to take advantage of the new Zenodo bucket upload API.
deleteFile()
Deletes a file for a record
ZenodoManager$deleteFile(recordId, fileId)
recordId
ID of the record
fileId
ID of the file to delete
getRecords()
Get the list of Zenodo records. By defaut the list of records will be returned by
page with a size of 10 results per page (default size of the Zenodo API). The parameter
q
allows to specify an ElasticSearch-compliant query to filter depositions
(default query is empty to retrieve all records). The argument all_versions
,
if set to TRUE allows to get all versions of records as part of the depositions list.
The argument exact
specifies that an exact matching is wished, in which case
paginated search will be disabled (only the first search page will be returned).
Examples of ElasticSearch queries for Zenodo can be found at https://help.zenodo.org/guides/search/.
ZenodoManager$getRecords(
q = "",
size = 10,
all_versions = FALSE,
exact = FALSE
)
q
Elastic-Search-compliant query, as object of class character
. Default is ""
size
number of records to be retrieved per request (paginated). Default is 10
all_versions
object of class logical
indicating if all versions of records have to be retrieved. Default is FALSE
exact
object of class logical
indicating if exact matching has to be applied. Default is TRUE
quiet
object of class logical
indicating if logs have to skipped. Default is FALSE
a list of ZenodoRecord
getRecordByConceptDOI()
Get Record by concept DOI
ZenodoManager$getRecordByConceptDOI(conceptdoi)
conceptdoi
the concept DOI
a object of class ZenodoRecord
getRecordByDOI()
Get Record by DOI
ZenodoManager$getRecordByDOI(doi)
doi
the DOI
a object of class ZenodoRecord
getRecordById()
Get Record by ID
ZenodoManager$getRecordById(recid)
recid
the record ID
a object of class ZenodoRecord
getRecordByConceptId()
Get Record by concept ID
ZenodoManager$getRecordByConceptId(conceptrecid)
conceptrecid
the concept ID
a object of class ZenodoRecord
clone()
The objects of this class are cloneable with this method.
ZenodoManager$clone(deep = FALSE)
deep
Whether to make a deep clone.
if (FALSE) {
ZENODO <- ZenodoManager$new(
url = "https://sandbox.zenodo.org/api",
token = "",
logger = "INFO"
)
#create (deposit) an empty record
newRec <- ZENODO$createEmptyRecord()
#create and fill a local (not yet deposited) record
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")
#deposit the record
myrec <- ZENODO$depositRecord(myrec)
#publish a record (with caution!!)
#this method will PUBLISH the deposition done earlier
ZENODO$publishRecord(myrec$id)
#With even more caution the publication can be done with a shortcut argument at deposit time
ZENODO$depositRecord(myrec, publish = TRUE)
#delete a record (by id)
#this methods only works for unpublished deposits
#(if a record is published, it cannot be deleted anymore!)
ZENODO$deleteRecord(myrec$id)
#HOW TO UPLOAD FILES to a deposit
#upload a file
ZENODO$uploadFile("path/to/your/file", record = myrec)
#list files
zen_files <- ZENODO$getFiles(myrec$id)
#delete a file?
ZENODO$deleteFile(myrec$id, zen_files[[1]]$id)
}
Run the code above in your browser using DataLab