Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
eblondel committed Mar 22, 2023
1 parent 2c9491a commit 1c4a787
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 22 deletions.
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
* [#114](https://github.com/eblondel/zen4R/issues/114) Avoid re-downloading existing files
* [#117](https://github.com/eblondel/zen4R/issues/117) Support single (organisation) name argument in `addContributor`
* [#119](https://github.com/eblondel/zen4R/issues/119) Support sandbox argument for ZenodoManager for easy use
* [#118](https://github.com/eblondel/zen4R/issues/118) Support sandbox-based controls for license, grant, community management methods


## [zen4R 0.8](https://cran.r-project.org/package=zen4R) | [![CRAN_Status_Badge](https://img.shields.io/badge/CRAN-published-blue.svg)](https://cran.r-project.org/package=zen4R)
Expand Down
27 changes: 16 additions & 11 deletions R/ZenodoRecord.R
Original file line number Diff line number Diff line change
Expand Up @@ -428,9 +428,10 @@ ZenodoRecord <- R6Class("ZenodoRecord",
#' @description Set license. The license should be set with the Zenodo id of the license. If not
#' recognized by Zenodo, the function will return an error. The list of licenses can
#' fetched with the \code{ZenodoManager} and the function \code{$getLicenses()}.
#' @param licenseId a license Id
setLicense = function(licenseId){
zen <- ZenodoManager$new()
#' @param licenseId a license Id
#' @param sandbox Use the Zenodo sandbox infrastructure as basis to control available licenses. Default is \code{FALSE}
setLicense = function(licenseId, sandbox = FALSE){
zen <- ZenodoManager$new(sandbox = sandbox)
zen_license <- zen$getLicenseById(licenseId)
if(!is.null(zen_license$status)){
errorMsg <- sprintf("License with id '%s' doesn't exist in Zenodo", licenseId)
Expand Down Expand Up @@ -651,21 +652,23 @@ ZenodoRecord <- R6Class("ZenodoRecord",
#' @param communities a vector or list of communities. Values should among known communities. The list of communities can
#' fetched with the \code{ZenodoManager} and the function \code{$getCommunities()}. Each community should be set with
#' the Zenodo id of the community. If not recognized by Zenodo, the function will return an error.
setCommunities = function(communities){
#' @param sandbox Use the Zenodo sandbox infrastructure as basis to control available communities. Default is \code{FALSE}
setCommunities = function(communities, sandbox = FALSE){
if(is.null(self$metadata$communities)) self$metadata$communities <- list()
for(community in communities){
self$addCommunity(community)
self$addCommunity(community, sandbox = sandbox)
}
},

#' @description Adds a community to the record metadata.
#' @param community community to add. The community should be set with the Zenodo id of the community.
#' If not recognized by Zenodo, the function will return an error. The list of communities can fetched
#' with the \code{ZenodoManager} and the function \code{$getCommunities()}.
#' @param sandbox Use the Zenodo sandbox infrastructure as basis to control available communities. Default is \code{FALSE}
#' @return \code{TRUE} if added, \code{FALSE} otherwise
addCommunity = function(community){
addCommunity = function(community, sandbox = FALSE){
added <- FALSE
zen <- ZenodoManager$new()
zen <- ZenodoManager$new(sandbox = sandbox)
if(is.null(self$metadata$communities)) self$metadata$communities <- list()
if(!(community %in% sapply(self$metadata$communities, function(x){x$identifier}))){
zen_community <- zen$getCommunityById(community)
Expand Down Expand Up @@ -702,21 +705,23 @@ ZenodoRecord <- R6Class("ZenodoRecord",
#' @param grants a vector or list of grants Values should among known grants The list of grants can
#' fetched with the \code{ZenodoManager} and the function \code{$getGrants()}. Each grant should be set with
#' the Zenodo id of the grant If not recognized by Zenodo, the function will raise a warning only.
setGrants = function(grants){
#' @param sandbox Use the Zenodo sandbox infrastructure as basis to control available grants. Default is \code{FALSE}
setGrants = function(grants, sandbox = FALSE){
if(is.null(self$metadata$grants)) self$metadata$grants <- list()
for(grant in grants){
self$addGrant(grant)
self$addGrant(grant, sandbox = sandbox)
}
},

#' @description Adds a grant to the record metadata.
#' @param grant grant to add. The grant should be set with the id of the grant. If not
#' recognized by Zenodo, the function will return an warning only. The list of grants can
#' fetched with the \code{ZenodoManager} and the function \code{$getGrants()}.
#' @param sandbox Use the Zenodo sandbox infrastructure as basis to control available grants. Default is \code{FALSE}
#' @return \code{TRUE} if added, \code{FALSE} otherwise
addGrant = function(grant){
addGrant = function(grant, sandbox = FALSE){
added <- FALSE
zen <- ZenodoManager$new()
zen <- ZenodoManager$new(sandbox = sandbox)
if(is.null(self$metadata$grants)) self$metadata$grants <- list()
if(!(grant %in% self$metadata$grants)){
if(regexpr("::", grant)>0){
Expand Down
20 changes: 15 additions & 5 deletions man/ZenodoRecord.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions tests/testthat/test_records.R
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ test_that("create and deposit record",{
myrec$setUploadType("publication")
myrec$setPublicationType("article")
myrec$addCreator(firstname = "John", lastname = "Doe", affiliation = "Independent")
myrec$setLicense("MIT")
expect_true(myrec$addCommunity("ecfunded"))
expect_false(myrec$addCommunity("ecfunded"))
myrec$setLicense("MIT", sandbox = TRUE)
expect_true(myrec$addCommunity("ecfunded", sandbox = TRUE))
expect_false(myrec$addCommunity("ecfunded", sandbox = TRUE))
myrec$setKeywords(c("R","package","software"))
myrec$addReference("Author et al., 2019. Title")
myrec$addReference("Fulano et al., 2018. Título")
myrec$addGrant("675680")
myrec$addGrant("675680", sandbox = TRUE)
myrec$setJournalTitle("Journal title")
myrec$setJournalVolume("1")
myrec$setJournalIssue("Issue 1")
Expand Down Expand Up @@ -103,8 +103,8 @@ test_that("create, deposit and publish record",{
myrec$setPublicationType("article")
myrec$addCreator(firstname = "John", lastname = "Doe", affiliation = "Independent")
myrec$addCreator(name = "Doe2, John2", affiliation = "Independent")
myrec$setLicense("mit")
myrec$addCommunity("ecfunded")
myrec$setLicense("mit", sandbox = TRUE)
myrec$addCommunity("ecfunded", sandbox = TRUE)
myrec$setKeywords(c("R","package","software"))
myrec$addReference("Author et al., 2019. Title")
myrec$addReference("Fulano et al., 2018. Título")
Expand Down

0 comments on commit 1c4a787

Please sign in to comment.