Bioconductor / BiocParallel

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

[patch 3] allow automatically exporting the global variables used in the function #192

Closed Jiefei-Wang closed 2 years ago

Jiefei-Wang commented 2 years ago

This pull request is based on patch 2. It supports automatically export variables/packages from the manager to the worker.

Use case 1

x <- "hello"
bplapply(1, function(i) x, BPPARAM = SnowParam(2))
# [[1]]
# [1] "hello"

Use case 2

library(S4Vectors)
bplapply(1, function(i) DataFrame(), BPPARAM = SnowParam(2))
# [[1]]
# DataFrame with 0 rows and 0 columns

It also allows the user to specify which variables to export, in the case where the auto-export feature does not work. E.g.

> x <- 10
> bar <- function() x
> foo <- function(x) bar()
> ## auto export would not be able to detect the variable "x"
> opts <- bpoptions(exports = "x")
> bplapply(1, foo, BPPARAM = SnowParam(), BPOPTIONS = opts)
[[1]]
[1] 10