Skip to content

Commit e320087

Browse files
committed
Merge branch 'Jiefei-Wang-user_null' into devel
- Closes #267. Closes #269.
2 parents 5ccc3e7 + 93a6b1e commit e320087

4 files changed

Lines changed: 45 additions & 1 deletion

File tree

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.0
4+
Version: 1.43.1
55
Authors@R: c(
66
person("Martin", "Morgan",
77
email = "mtmorgan.bioc@gmail.com",

NEWS

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
CHANGES IN VERSION 1.44
2+
-----------------------
3+
4+
NEW FEATURES
5+
6+
o (1.43.1) Support NULL return value from bplapply. see
7+
<https://github.com/Bioconductor/BiocParallel/issues/267>
8+
<https://github.com/Bioconductor/BiocParallel/pull/269>
9+
110
CHANGES IN VERSION 1.42
211
-----------------------
312

R/bploop.R

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,16 @@
1+
### - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
2+
### utils
3+
4+
## a reserved value to represent a NULL value in X in bplapply
5+
.bp_null <- function(){
6+
structure(list(), class = "bp_null")
7+
}
8+
9+
.is_bp_null <- function(x){
10+
inherits(x, "bp_null")
11+
}
12+
13+
114
### - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
215
### Manager loop used by SOCK, MPI and FORK
316

@@ -81,6 +94,12 @@
8194
.bploop_lapply_iter <-
8295
function(X, redo_index, elements_per_task)
8396
{
97+
## replace the user-provided NULL with a reserved NULL
98+
null_indices <- which(vapply(X, is.null, logical(1)))
99+
for (null_index in null_indices) {
100+
X[[null_index]] <- .bp_null()
101+
}
102+
84103
redo_n <- length(redo_index)
85104
redo_i <- 1L
86105
x_n <- length(X)
@@ -270,6 +289,13 @@
270289
warning("first invocation of 'ITER()' returned NULL")
271290
break
272291
}
292+
293+
## Replace the reserved NULL value with a real NULL
294+
null_indices <- which(vapply(value, .is_bp_null, logical(1)))
295+
for (null_index in null_indices) {
296+
value[null_index] <- list(NULL)
297+
}
298+
273299
args <- ARGFUN(value, seed)
274300
task <- .EXEC(
275301
total + 1L, .workerLapply,

inst/unitTests/test_bplapply.R

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,3 +150,12 @@ test_bplapply_auto_export <- function(){
150150
bpexportvariables(p) <- FALSE
151151
checkException(bplapply(1:2, fun2, BPPARAM = p), silent = TRUE)
152152
}
153+
154+
155+
test_bplapply_null_value_in_input <- function(){
156+
p <- SerialParam()
157+
FUN <- function(x) x
158+
X <- list(a = 1, b = 2, c = NULL, d = 4)
159+
result <- bptry(bplapply(X, FUN, BPPARAM = p))
160+
checkIdentical(X, result)
161+
}

0 commit comments

Comments
 (0)