diff --git a/NEWS.md b/NEWS.md
index 9b6d947..a5b7c9a 100644
--- a/NEWS.md
+++ b/NEWS.md
@@ -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) | [](https://cran.r-project.org/package=zen4R)
diff --git a/R/ZenodoRecord.R b/R/ZenodoRecord.R
index 5a98012..c828d89 100644
--- a/R/ZenodoRecord.R
+++ b/R/ZenodoRecord.R
@@ -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)
@@ -651,10 +652,11 @@ 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)
}
},
@@ -662,10 +664,11 @@ ZenodoRecord <- R6Class("ZenodoRecord",
#' @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)
@@ -702,10 +705,11 @@ 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)
}
},
@@ -713,10 +717,11 @@ ZenodoRecord <- R6Class("ZenodoRecord",
#' @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){
diff --git a/man/ZenodoRecord.Rd b/man/ZenodoRecord.Rd
index 7f85d09..590e82d 100644
--- a/man/ZenodoRecord.Rd
+++ b/man/ZenodoRecord.Rd
@@ -745,13 +745,15 @@ 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()}.
\subsection{Usage}{
-\if{html}{\out{
}}\preformatted{ZenodoRecord$setLicense(licenseId)}\if{html}{\out{
}}
+\if{html}{\out{}}\preformatted{ZenodoRecord$setLicense(licenseId, sandbox = FALSE)}\if{html}{\out{
}}
}
\subsection{Arguments}{
\if{html}{\out{}}
\describe{
\item{\code{licenseId}}{a license Id}
+
+\item{\code{sandbox}}{Use the Zenodo sandbox infrastructure as basis to control available licenses. Default is \code{FALSE}}
}
\if{html}{\out{
}}
}
@@ -1058,7 +1060,7 @@ Set notes. HTML is not allowed
\subsection{Method \code{setCommunities()}}{
Set a vector of character strings identifying communities
\subsection{Usage}{
-\if{html}{\out{}}\preformatted{ZenodoRecord$setCommunities(communities)}\if{html}{\out{
}}
+\if{html}{\out{}}\preformatted{ZenodoRecord$setCommunities(communities, sandbox = FALSE)}\if{html}{\out{
}}
}
\subsection{Arguments}{
@@ -1067,6 +1069,8 @@ Set a vector of character strings identifying communities
\item{\code{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.}
+
+\item{\code{sandbox}}{Use the Zenodo sandbox infrastructure as basis to control available communities. Default is \code{FALSE}}
}
\if{html}{\out{}}
}
@@ -1077,7 +1081,7 @@ the Zenodo id of the community. If not recognized by Zenodo, the function will r
\subsection{Method \code{addCommunity()}}{
Adds a community to the record metadata.
\subsection{Usage}{
-\if{html}{\out{}}\preformatted{ZenodoRecord$addCommunity(community)}\if{html}{\out{
}}
+\if{html}{\out{}}\preformatted{ZenodoRecord$addCommunity(community, sandbox = FALSE)}\if{html}{\out{
}}
}
\subsection{Arguments}{
@@ -1086,6 +1090,8 @@ Adds a community to the record metadata.
\item{\code{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()}.}
+
+\item{\code{sandbox}}{Use the Zenodo sandbox infrastructure as basis to control available communities. Default is \code{FALSE}}
}
\if{html}{\out{}}
}
@@ -1119,7 +1125,7 @@ Removes a community from the record metadata.
\subsection{Method \code{setGrants()}}{
Set a vector of character strings identifying grants
\subsection{Usage}{
-\if{html}{\out{}}\preformatted{ZenodoRecord$setGrants(grants)}\if{html}{\out{
}}
+\if{html}{\out{}}\preformatted{ZenodoRecord$setGrants(grants, sandbox = FALSE)}\if{html}{\out{
}}
}
\subsection{Arguments}{
@@ -1128,6 +1134,8 @@ Set a vector of character strings identifying grants
\item{\code{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.}
+
+\item{\code{sandbox}}{Use the Zenodo sandbox infrastructure as basis to control available grants. Default is \code{FALSE}}
}
\if{html}{\out{}}
}
@@ -1138,7 +1146,7 @@ the Zenodo id of the grant If not recognized by Zenodo, the function will raise
\subsection{Method \code{addGrant()}}{
Adds a grant to the record metadata.
\subsection{Usage}{
-\if{html}{\out{}}\preformatted{ZenodoRecord$addGrant(grant)}\if{html}{\out{
}}
+\if{html}{\out{}}\preformatted{ZenodoRecord$addGrant(grant, sandbox = FALSE)}\if{html}{\out{
}}
}
\subsection{Arguments}{
@@ -1147,6 +1155,8 @@ Adds a grant to the record metadata.
\item{\code{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()}.}
+
+\item{\code{sandbox}}{Use the Zenodo sandbox infrastructure as basis to control available grants. Default is \code{FALSE}}
}
\if{html}{\out{}}
}
diff --git a/tests/testthat/test_records.R b/tests/testthat/test_records.R
index 2205021..8532973 100644
--- a/tests/testthat/test_records.R
+++ b/tests/testthat/test_records.R
@@ -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")
@@ -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")