From 4b85fdf076b3e1b7282a2156349ef735704b8a77 Mon Sep 17 00:00:00 2001 From: florisvdh Date: Thu, 3 Sep 2020 10:18:43 +0200 Subject: [PATCH 1/2] download_zenodo(): update examples --- R/zen4R_downloader.R | 1 + man/download_zenodo.Rd | 1 + 2 files changed, 2 insertions(+) diff --git a/R/zen4R_downloader.R b/R/zen4R_downloader.R index 057e552..42ff5e9 100644 --- a/R/zen4R_downloader.R +++ b/R/zen4R_downloader.R @@ -9,6 +9,7 @@ #' #simple download (sequential) #' download_zenodo("10.5281/zenodo.2547036") #' +#' library(parallel) #' #download files as parallel using a cluster approach (for both Unix/Win systems) #' download_zenodo("10.5281/zenodo.2547036", #' parallel = TRUE, parallel_handler = parLapply, cl = makeCluster(2)) diff --git a/man/download_zenodo.Rd b/man/download_zenodo.Rd index b630d83..3a0f39a 100644 --- a/man/download_zenodo.Rd +++ b/man/download_zenodo.Rd @@ -29,6 +29,7 @@ record, identified by its DOI or concept DOI. #simple download (sequential) download_zenodo("10.5281/zenodo.2547036") + library(parallel) #download files as parallel using a cluster approach (for both Unix/Win systems) download_zenodo("10.5281/zenodo.2547036", parallel = TRUE, parallel_handler = parLapply, cl = makeCluster(2)) From d9a72d643f468d7695bb87bd80402cc1c29f2b75 Mon Sep 17 00:00:00 2001 From: florisvdh Date: Thu, 3 Sep 2020 10:44:28 +0200 Subject: [PATCH 2/2] move parallel into suggests, drop import --- DESCRIPTION | 4 ++-- NAMESPACE | 1 - R/ZenodoRecord.R | 7 ++++++- R/zen4R.R | 1 - 4 files changed, 8 insertions(+), 5 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 9f00b13..7fab5fb 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -10,8 +10,8 @@ Authors@R: c( person("Floris", "Vanderhaeghe", role = c("ctb"), comment = c(ORCID = "0000-0002-6378-6229"))) Maintainer: Emmanuel Blondel Depends: R (>= 3.3.0), methods -Imports: R6, httr, jsonlite, xml2, keyring, tools, parallel -Suggests: testthat +Imports: R6, httr, jsonlite, xml2, keyring, tools +Suggests: testthat, parallel Description: Provides an Interface to 'Zenodo' () REST API, including management of depositions, attribution of DOIs by 'Zenodo' and upload of files. diff --git a/NAMESPACE b/NAMESPACE index ffb0212..f83fe9f 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -12,6 +12,5 @@ import(keyring) import(methods) import(xml2) importFrom(R6,R6Class) -importFrom(parallel,mclapply) importFrom(tools,file_path_as_absolute) importFrom(tools,md5sum) diff --git a/R/ZenodoRecord.R b/R/ZenodoRecord.R index 8dd4116..0c07985 100644 --- a/R/ZenodoRecord.R +++ b/R/ZenodoRecord.R @@ -1196,10 +1196,15 @@ ZenodoRecord <- R6Class("ZenodoRecord", } if(!is.null(parallel_handler)){ if(!is.null(cl)){ + if (!requireNamespace("parallel", quietly = TRUE)) { + errMsg <- "Package \"parallel\" needed for cluster-based parallel handler. Please install it." + self$ERROR(errMsg) + stop(errMsg) + } if (!quiet) self$INFO("Using cluster-based parallel handler (cluster 'cl' argument specified)") if (!quiet) self$INFO(files_summary) invisible(parallel_handler(cl, self$files, download_file, ...)) - try(stopCluster(cl)) + try(parallel::stopCluster(cl)) }else{ if (!quiet) self$INFO("Using non cluster-based (no cluster 'cl' argument specified)") if (!quiet) self$INFO(files_summary) diff --git a/R/zen4R.R b/R/zen4R.R index 6f3a88e..43c52ea 100644 --- a/R/zen4R.R +++ b/R/zen4R.R @@ -11,7 +11,6 @@ #' @import keyring #' @importFrom tools file_path_as_absolute #' @importFrom tools md5sum -#' @importFrom parallel mclapply #' #' @title Interface to 'Zenodo' REST API #' @description Provides an Interface to 'Zenodo' () REST API,