Skip to content

Commit 5a03395

Browse files
bschilderclaude
andcommitted
Add requireNamespace guards for Suggests deps (echolocatoR#151)
- MOTIFBREAKR.R: guard BSgenome, motifbreakR, MotifDb with stop + install instructions - MOTIFBREAKR_plot.R: same guards for motifbreakR, MotifDb, BSgenome.Hsapiens.UCSC.hg19 - MOTIFBREAKR_calc_pvals.R: same guards for motifbreakR, MotifDb, BSgenome - test_enrichment.R: guard regioneR with stop + install instructions All bare requireNamespace() calls now stop with actionable BiocManager::install() messages. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 8f2c3b1 commit 5a03395

4 files changed

Lines changed: 37 additions & 11 deletions

File tree

R/MOTIFBREAKR.R

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,16 @@ MOTIFBREAKR <- function(rsid_list,
8080
granularity = NULL,
8181
nThread = 1,
8282
verbose = TRUE){
83-
requireNamespace("BSgenome")
84-
requireNamespace("motifbreakR")
83+
if (!requireNamespace("BSgenome", quietly = TRUE)) {
84+
stop("Package 'BSgenome' is required for motifbreakR.\n",
85+
"Install it with: BiocManager::install('BSgenome')",
86+
call. = FALSE)
87+
}
88+
if (!requireNamespace("motifbreakR", quietly = TRUE)) {
89+
stop("Package 'motifbreakR' is required but not installed.\n",
90+
"Install it with: BiocManager::install('motifbreakR')",
91+
call. = FALSE)
92+
}
8593
# echoverseTemplate:::args2vars(MOTIFBREAKR)
8694

8795
#### Select genome build ####
@@ -102,7 +110,14 @@ MOTIFBREAKR <- function(rsid_list,
102110
dbSNP = gb_list$dbSNP,
103111
search.genome = gb_list$search.genome);
104112
#### Subset motif databases ####
105-
if(is.null(pwmList)){pwmList <- MotifDb::MotifDb}
113+
if(is.null(pwmList)){
114+
if (!requireNamespace("MotifDb", quietly = TRUE)) {
115+
stop("Package 'MotifDb' is required for motifbreakR.\n",
116+
"Install it with: BiocManager::install('MotifDb')",
117+
call. = FALSE)
118+
}
119+
pwmList <- MotifDb::MotifDb
120+
}
106121
if(!is.null(organism)){
107122
messager("Filtering pwmList to only include organism:",organism)
108123
pwmList <- pwmList[grep(paste0("^",organism),names(pwmList),

R/MOTIFBREAKR_calc_pvals.R

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,13 @@ MOTIFBREAKR_calc_pvals <- function(mb_res,
2626
nThread = 1,
2727
results_dir = file.path(tempdir(),"results"),
2828
verbose = TRUE){
29-
requireNamespace("motifbreakR");
30-
requireNamespace("MotifDb");
31-
requireNamespace("BSgenome");
29+
for (pkg in c("motifbreakR", "MotifDb", "BSgenome")) {
30+
if (!requireNamespace(pkg, quietly = TRUE)) {
31+
stop("Package '", pkg, "' is required but not installed.\n",
32+
"Install it with: BiocManager::install('", pkg, "')",
33+
call. = FALSE)
34+
}
35+
}
3236
#### Calculate p-values ####
3337
messager("+ MOTIFBREAKR:: Calculating p-values for",
3438
length(mb_res),"RSID(s)...", v=verbose)

R/MOTIFBREAKR_plot.R

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,13 @@ MOTIFBREAKR_plot <- function(mb_res,
5050
width=7,
5151
verbose=TRUE){
5252

53-
requireNamespace("motifbreakR")
54-
requireNamespace("MotifDb")
55-
requireNamespace("BSgenome.Hsapiens.UCSC.hg19")
56-
requireNamespace("grDevices")
53+
for (pkg in c("motifbreakR", "MotifDb", "BSgenome.Hsapiens.UCSC.hg19")) {
54+
if (!requireNamespace(pkg, quietly = TRUE)) {
55+
stop("Package '", pkg, "' is required but not installed.\n",
56+
"Install it with: BiocManager::install('", pkg, "')",
57+
call. = FALSE)
58+
}
59+
}
5760
id <- NULL;
5861

5962
mb_res <- echodata::dt_to_granges(dat = mb_res,

R/test_enrichment.R

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,11 @@ test_enrichment <- function(grlist1,
5454
verbose = TRUE,
5555
...){
5656

57-
requireNamespace("regioneR")
57+
if (!requireNamespace("regioneR", quietly = TRUE)) {
58+
stop("Package 'regioneR' is required but not installed.\n",
59+
"Install it with: BiocManager::install('regioneR')",
60+
call. = FALSE)
61+
}
5862
#### Check inputs ####
5963
grlist1 <- check_grlist(grlist=grlist1,
6064
prefix = "grlist1",

0 commit comments

Comments
 (0)