Bioconductor / BiocParallel

Bioconductor facilities for parallel evaluation
https://bioconductor.org/packages/BiocParallel
67 stars 29 forks source link

"foreach" %in% loadedNamespaces() instead of "package:foreach" %in% search()? #251

Closed HenrikBengtsson closed 1 year ago

HenrikBengtsson commented 1 year ago

I just noticed:

https://github.com/Bioconductor/BiocParallel/blob/4a48a7eb2ac11d9d08589b1926eff35242d472f6/R/DoparParam-class.R#L21-L28

This checks if foreach is attached, and if not, then it's loaded. Can that be replaced for a check if the package is loaded, i.e.

 if (!"foreach" %in% loadedNamespaces()) {
   ...
}

?

HenrikBengtsson commented 1 year ago

Oh, looking at the rest of the code, I think:

if (!requireNamespace("foreach", quietly = TRUE)) {
  stop("DoparParam() requires the 'foreach' package") 
}

is what you want here.