Skip to content

Commit b959552

Browse files
BUG FIX: foreach(..., .errorhandling = "pass") %dofuture% { ... }` now works as expected [#86]
1 parent 2eb89e6 commit b959552

File tree

5 files changed

+31
-17
lines changed

5 files changed

+31
-17
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
Package: doFuture
2-
Version: 1.1.0-9002
2+
Version: 1.1.0-9003
33
Title: Use Foreach to Parallelize via the Future Framework
44
Depends:
55
foreach (>= 1.5.0),

NEWS.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
# Version (development version)
22

3-
* ...
3+
## Bug Fixes
4+
5+
* `foreach(...) %dofuture% { ... }` would signal errors, despite
6+
using `.errorhandling = "pass"` or `.errorhandling = "remove"`.
7+
This was originally by design, because all errors should be errors,
8+
but have since been convinced it was a design mistake.
49

510

611
# Version 1.1.0 (2025-05-19)

R/doFuture2.R

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -70,19 +70,24 @@ doFuture2 <- function(obj, expr, envir, data) { #nolint
7070
options[name] <- opts[name]
7171
}
7272
options(future.disposable = NULL)
73-
74-
errors <- options[["errors"]]
75-
if (is.null(errors)) {
76-
errors <- "future"
77-
} else if (is.character(errors)) {
78-
if (length(errors) != 1L) {
79-
stop(sprintf("Element 'errors' of '.options.future' should be of length one': [n = %d] %s", length(errors), paste(sQuote(errors), collapse = ", ")))
80-
}
81-
if (! errors %in% c("future", "foreach")) {
82-
stop(sprintf("Unknown value of '.options.future' element 'errors': %s", sQuote(errors)))
83-
}
73+
74+
error_handling <- obj$errorHandling
75+
if (!identical(error_handling, "stop")) {
76+
errors <- "foreach"
8477
} else {
85-
stop("Unknown type of '.options.future' element 'errors': ", mode(errors))
78+
errors <- options[["errors"]]
79+
if (is.null(errors)) {
80+
errors <- "future"
81+
} else if (is.character(errors)) {
82+
if (length(errors) != 1L) {
83+
stop(sprintf("Element 'errors' of '.options.future' should be of length one': [n = %d] %s", length(errors), paste(sQuote(errors), collapse = ", ")))
84+
}
85+
if (! errors %in% c("future", "foreach")) {
86+
stop(sprintf("Unknown value of '.options.future' element 'errors': %s", sQuote(errors)))
87+
}
88+
} else {
89+
stop("Unknown type of '.options.future' element 'errors': ", mode(errors))
90+
}
8691
}
8792

8893

@@ -630,7 +635,6 @@ elements in 'X' (= %d). There were in total %d chunks and %d elements (%s)",
630635
## ... or as traditionally with %dopar%, which throws an error
631636
## or return the combined results
632637
## NOTE: This is adopted from foreach:::doSEQ()
633-
error_handling <- obj$errorHandling
634638
if (debug) {
635639
mdebugf("processing errors (handler = %s)", sQuote(error_handling))
636640
}

R/dofuture_OP.R

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,16 @@
1414
#' When using `%dofuture%`:
1515
#'
1616
#' * there is no need to use `registerDoFuture()`
17+
#'
1718
#' * there is no need to use `%dorng%` of the **doRNG** package
1819
#' (but you need to specify `.options.future = list(seed = TRUE)`
1920
#' whenever using random numbers in the `expr` expression)
21+
#'
2022
#' * global variables and packages are identified automatically by
2123
#' the \pkg{future} framework
22-
#' * errors are relayed as-is (with `%dopar%` they are captured and modified)
24+
#'
25+
#' * errors are relayed as-is with the default `.errorhandling = "stop"`,
26+
#' whereas with `%dopar%` they are captured and modified.
2327
#'
2428
#'
2529
#' @section Global variables and packages:

man/grapes-dofuture-grapes.Rd

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)