diff --git a/DESCRIPTION b/DESCRIPTION index 68fb74e..fe44983 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Package: BiocParallel Type: Package Title: Bioconductor facilities for parallel evaluation -Version: 1.41.2 +Version: 1.41.3 Authors@R: c( person("Martin", "Morgan", email = "mtmorgan.bioc@gmail.com", diff --git a/R/bploop.R b/R/bploop.R index 49b9558..3eee6ed 100644 --- a/R/bploop.R +++ b/R/bploop.R @@ -1,3 +1,16 @@ +### - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +### utils + +## a reserved value to represent a NULL value in X in bplapply +.bp_null <- function(){ + structure(list(), class = "bp_null") +} + +.is_bp_null <- function(x){ + inherits(x, "bp_null") +} + + ### - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ### Manager loop used by SOCK, MPI and FORK @@ -81,6 +94,12 @@ .bploop_lapply_iter <- function(X, redo_index, elements_per_task) { + ## replace the user-provided NULL with a reserved NULL + null_indices <- which(vapply(X, is.null, logical(1))) + for (null_index in null_indices) { + X[[null_index]] <- .bp_null() + } + redo_n <- length(redo_index) redo_i <- 1L x_n <- length(X) @@ -270,6 +289,13 @@ warning("first invocation of 'ITER()' returned NULL") break } + + ## Replace the reserved NULL value with a real NULL + null_indices <- which(vapply(value, .is_bp_null, logical(1))) + for (null_index in null_indices) { + value[null_index] <- list(NULL) + } + args <- ARGFUN(value, seed) task <- .EXEC( total + 1L, .workerLapply, diff --git a/inst/unitTests/test_bplapply.R b/inst/unitTests/test_bplapply.R index b1e300d..64c26b6 100644 --- a/inst/unitTests/test_bplapply.R +++ b/inst/unitTests/test_bplapply.R @@ -150,3 +150,12 @@ test_bplapply_auto_export <- function(){ bpexportvariables(p) <- FALSE checkException(bplapply(1:2, fun2, BPPARAM = p), silent = TRUE) } + + +test_bplapply_null_value_in_input <- function(){ + p <- SerialParam() + FUN <- function(x) x + X <- list(a = 1, b = 2, c = NULL, d = 4) + result <- bptry(bplapply(X, FUN, BPPARAM = p)) + checkIdentical(X, result) +}