From dcd088ee8129ae687e485bc97e2f84e335b33d16 Mon Sep 17 00:00:00 2001 From: Laurent Gatto Date: Sat, 16 Mar 2024 11:05:12 +0100 Subject: [PATCH 1/6] check connectivity before creating hub accessors --- R/zzz.R | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/R/zzz.R b/R/zzz.R index 4354388..372885d 100644 --- a/R/zzz.R +++ b/R/zzz.R @@ -3,11 +3,15 @@ .onLoad <- function(libname, pkgname) { fls <- dir(system.file("extdata", package = pkgname), full.names = TRUE, pattern = "metadata") - sapply(fls, - function(fl) { - titles <- read.csv(fl, stringsAsFactors = FALSE)$Title - ExperimentHub::createHubAccessors(pkgname, titles) - }) + if (curl::has_internet()) { + sapply(fls, + function(fl) { + titles <- read.csv(fl, stringsAsFactors = FALSE)$Title + ExperimentHub::createHubAccessors(pkgname, titles) + }) + } else { + warning("Not internet connectivity. Unable to create Hub accessors.") + } } .onAttach <- function(libname, pkgname) { From c3313784042a2adc103556b72d313f603fdf3eff Mon Sep 17 00:00:00 2001 From: Laurent Gatto Date: Sat, 16 Mar 2024 11:10:36 +0100 Subject: [PATCH 2/6] no call in warning --- R/zzz.R | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/R/zzz.R b/R/zzz.R index 372885d..531aa93 100644 --- a/R/zzz.R +++ b/R/zzz.R @@ -10,7 +10,8 @@ ExperimentHub::createHubAccessors(pkgname, titles) }) } else { - warning("Not internet connectivity. Unable to create Hub accessors.") + warning("Not internet connectivity. Unable to create Hub accessors.", + call. = FALSE) } } From 64e45d82bd42eb31db0c09c7c511d2348984526b Mon Sep 17 00:00:00 2001 From: Laurent Gatto Date: Sat, 16 Mar 2024 11:41:26 +0100 Subject: [PATCH 3/6] import from curl --- DESCRIPTION | 1 + NAMESPACE | 1 + R/zzz.R | 1 + 3 files changed, 3 insertions(+) diff --git a/DESCRIPTION b/DESCRIPTION index feb68be..f98181f 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -33,6 +33,7 @@ Imports: AnnotationHub, BiocFileCache, httr2, + curl, tibble License: Artistic-2.0 Encoding: UTF-8 diff --git a/NAMESPACE b/NAMESPACE index cee2768..461da59 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -30,6 +30,7 @@ importFrom(BiocFileCache,bfcquery) importFrom(BiocFileCache,bfcrpath) importFrom(ExperimentHub,ExperimentHub) importFrom(ExperimentHub,createHubAccessors) +importFrom(curl,has_internet) importFrom(httr2,req_perform) importFrom(httr2,request) importFrom(httr2,resp_body_json) diff --git a/R/zzz.R b/R/zzz.R index 531aa93..e40f35c 100644 --- a/R/zzz.R +++ b/R/zzz.R @@ -1,4 +1,5 @@ ##' @importFrom utils read.csv +##' @importFrom curl has_internet ##' @importFrom ExperimentHub createHubAccessors .onLoad <- function(libname, pkgname) { fls <- dir(system.file("extdata", package = pkgname), From 30148897b38fe4b2d353b401fd85e1f05344fb52 Mon Sep 17 00:00:00 2001 From: Laurent Gatto Date: Sun, 17 Mar 2024 15:30:21 +0100 Subject: [PATCH 4/6] helper function creates hub accessors --- DESCRIPTION | 2 +- NEWS.md | 5 +++++ R/loading_functions.R | 15 ++++++++++++++- R/zzz.R | 15 +++------------ 4 files changed, 23 insertions(+), 14 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index f98181f..5213434 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Package: depmap Type: Package Title: Cancer Dependency Map Data Package -Version: 1.17.4 +Version: 1.17.5 Authors@R: c(person(given = "Laurent", family = "Gatto", email = "laurent.gatto@uclouvain.be", comment = c(ORCID = "0000-0002-1520-2268"), diff --git a/NEWS.md b/NEWS.md index 5f38cc6..3c53764 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,10 @@ # depmap 1.17 +## Changes in version 1.17.5 + +- Check if there's internet connectivity before creating hub + accessors. + ## Changes in version 1.17.4 - Fix .onLoad() to create Hub accessors for all experiments, including diff --git a/R/loading_functions.R b/R/loading_functions.R index fb00338..8958a5f 100644 --- a/R/loading_functions.R +++ b/R/loading_functions.R @@ -1,3 +1,16 @@ +##' @importFrom utils read.csv +##' @importFrom ExperimentHub createHubAccessors +.createDepMapHubAccessors <- function() { + fls <- dir(system.file("extdata", package = "depmap"), + full.names = TRUE, pattern = "metadata") + sapply(fls, + function(fl) { + titles <- read.csv(fl, stringsAsFactors = FALSE)$Title + ExperimentHub::createHubAccessors(pkgname, titles) + }) +} + + ##' @importFrom AnnotationHub query ##' @importFrom ExperimentHub ExperimentHub @@ -9,7 +22,7 @@ depmap_data_loading <- function(name) { } #' @export -depmap_rnai <- function() +depmap_rnai <- function() depmap_data_loading("rnai") #' @export diff --git a/R/zzz.R b/R/zzz.R index e40f35c..15f1202 100644 --- a/R/zzz.R +++ b/R/zzz.R @@ -1,19 +1,10 @@ -##' @importFrom utils read.csv ##' @importFrom curl has_internet -##' @importFrom ExperimentHub createHubAccessors .onLoad <- function(libname, pkgname) { - fls <- dir(system.file("extdata", package = pkgname), - full.names = TRUE, pattern = "metadata") - if (curl::has_internet()) { - sapply(fls, - function(fl) { - titles <- read.csv(fl, stringsAsFactors = FALSE)$Title - ExperimentHub::createHubAccessors(pkgname, titles) - }) - } else { + if (curl::has_internet()) + .createDepMapHubAccessors() + else warning("Not internet connectivity. Unable to create Hub accessors.", call. = FALSE) - } } .onAttach <- function(libname, pkgname) { From d634df7f3fe850bd5bbb8ac38718b1029fe699a7 Mon Sep 17 00:00:00 2001 From: Laurent Gatto Date: Sun, 17 Mar 2024 15:45:36 +0100 Subject: [PATCH 5/6] fix error --- R/loading_functions.R | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/R/loading_functions.R b/R/loading_functions.R index 8958a5f..413e681 100644 --- a/R/loading_functions.R +++ b/R/loading_functions.R @@ -1,7 +1,7 @@ ##' @importFrom utils read.csv ##' @importFrom ExperimentHub createHubAccessors -.createDepMapHubAccessors <- function() { - fls <- dir(system.file("extdata", package = "depmap"), +.createDepMapHubAccessors <- function(pkgname = "depmap") { + fls <- dir(system.file("extdata", package), full.names = TRUE, pattern = "metadata") sapply(fls, function(fl) { From 870d89e0014aa81122392b85f0534cd8682f3175 Mon Sep 17 00:00:00 2001 From: Laurent Gatto Date: Sun, 17 Mar 2024 15:54:06 +0100 Subject: [PATCH 6/6] fix again --- R/loading_functions.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/loading_functions.R b/R/loading_functions.R index 413e681..822a901 100644 --- a/R/loading_functions.R +++ b/R/loading_functions.R @@ -1,7 +1,7 @@ ##' @importFrom utils read.csv ##' @importFrom ExperimentHub createHubAccessors .createDepMapHubAccessors <- function(pkgname = "depmap") { - fls <- dir(system.file("extdata", package), + fls <- dir(system.file("extdata", pkgname), full.names = TRUE, pattern = "metadata") sapply(fls, function(fl) {