Skip to content

Commit 9e2db5d

Browse files
committed
Merge branch 'Jiefei-Wang-force_load' into devel
- Closes #262. Closes #270
2 parents e320087 + 9ea06b9 commit 9e2db5d

File tree

4 files changed

+32
-2
lines changed

4 files changed

+32
-2
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Package: BiocParallel
22
Type: Package
33
Title: Bioconductor facilities for parallel evaluation
4-
Version: 1.43.1
4+
Version: 1.43.2
55
Authors@R: c(
66
person("Martin", "Morgan",
77
email = "[email protected]",

NEWS

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,11 @@ CHANGES IN VERSION 1.44
33

44
NEW FEATURES
55

6-
o (1.43.1) Support NULL return value from bplapply. see
6+
o (1.43.2) Lazy-load S4 classes in workers; see
7+
<https://github.com/Bioconductor/BiocParallel/issues/262>
8+
<https://github.com/Bioconductor/BiocParallel/pull/270>
9+
10+
o (1.43.1) Support NULL return value from bplapply; see
711
<https://github.com/Bioconductor/BiocParallel/issues/267>
812
<https://github.com/Bioconductor/BiocParallel/pull/269>
913

R/utilities.R

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,3 +129,26 @@
129129
timeout <- Inf
130130
timeout
131131
}
132+
133+
## This function walks through a nested list and attempts to trigger
134+
## loading of any encountered S4 class definitions using getClassDef().
135+
##
136+
## Limitations:
137+
## - It does NOT guarantee that all required packages will be loaded,
138+
## because S4 objects may be hidden in attributes, environments, or other
139+
## non-list structures that are not traversed here.
140+
.autoload_s4_classes <- function(obj) {
141+
seen <- character()
142+
recurse <- function(x) {
143+
if (isS4(x)) {
144+
cl <- class(x)
145+
if (!cl %in% seen) {
146+
seen <<- c(seen, cl)
147+
methods::getClassDef(cl)
148+
}
149+
} else if (is.list(x)) {
150+
lapply(x, recurse)
151+
}
152+
}
153+
recurse(obj)
154+
}

R/worker.R

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,9 @@
311311

312312
t1 <- proc.time()
313313
value <- tryCatch({
314+
## Lazy loading causes some packages fail to load in the worker
315+
## environment. This works in 99% cases (see function comments).
316+
.autoload_s4_classes(msg$data$args$X)
314317
do.call(msg$data$fun, msg$data$args)
315318
}, error=function(e) {
316319
## return as 'list()' because msg$fun has lapply semantics

0 commit comments

Comments
 (0)