Skip to content

Commit c9a0812

Browse files
BUG FIX: registerDoFuture() would return an invalid 'DoPar' object if there was no %dopar% registered
1 parent 7d2a11e commit c9a0812

File tree

6 files changed

+72
-64
lines changed

6 files changed

+72
-64
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.0.2-9023
2+
Version: 1.0.2-9026
33
Title: Use Foreach to Parallelize via the Future Framework
44
Depends:
55
foreach (>= 1.5.0),

NAMESPACE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ importFrom(foreach,getErrorIndex)
99
importFrom(foreach,getErrorValue)
1010
importFrom(foreach,getResult)
1111
importFrom(foreach,makeAccum)
12+
importFrom(foreach,registerDoSEQ)
1213
importFrom(foreach,setDoPar)
1314
importFrom(future,Future)
1415
importFrom(future,FutureError)

NEWS.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Version 1.0.2-9022 (2025-05-19)
1+
# Version 1.0.2-9026 (2025-05-19)
22

33
## New Features
44

@@ -26,6 +26,12 @@
2626
you to effectively make that the same as `foreach(...) %dofuture%
2727
{ ... }`.
2828

29+
## Bug Fixes
30+
31+
* `registerDoFuture()` would return an invalid `DoPar` object if
32+
there was no `%dopar%` registered. Now it returns an `DoPar` object
33+
as if `foreach::registerDoSEQ()` had been called before.
34+
2935

3036
# Version 1.0.2 (2025-03-15)
3137

R/registerDoFuture.R

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -241,20 +241,23 @@ registerDoFuture <- function(flavor = c("%dopar%", "%dofuture%")) { #nolint
241241
}
242242

243243

244+
#' @importFrom foreach registerDoSEQ
244245
.getDoPar <- function() {
245246
ns <- getNamespace("foreach")
246247
.foreachGlobals <- get(".foreachGlobals", envir = ns)
247248
if (exists("fun", envir = .foreachGlobals, inherits = FALSE)) {
248-
structure(list(
249+
res <- structure(list(
249250
fun = .foreachGlobals$fun,
250-
data = .foreachGlobals$data,
251+
data = .foreachGlobals$data,
251252
info = .foreachGlobals$info
252253
), class = "DoPar")
254+
if (is.null(res[["info"]])) res[["info"]] <- NULL
253255
} else {
254-
structure(list(
256+
res <- structure(list(
255257
fun = get("doSEQ", mode = "function", envir = ns),
256258
data = NULL,
257-
info = NULL
259+
info = environment(registerDoSEQ)[["info"]]
258260
), class = c("DoPar", "DoSeq"))
259261
}
262+
res
260263
}

R/with.DoPar.R

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,10 @@ with.DoPar <- function(data, expr, ..., local = FALSE, envir = parent.frame()) {
2727
## It won't work with doParallel::registerDoParallel(), because it does not
2828
## return the previous adapter. Only registerDoFuture() does that.
2929
oldDoPar <- data
30+
3031

3132
undoDoPar <- function() {
32-
setDoPar(
33-
fun = oldDoPar[["fun"]],
34-
data = oldDoPar[["data"]],
35-
info = oldDoPar[["info"]]
36-
)
33+
do.call(setDoPar, args = oldDoPar)
3734
}
3835

3936
if (local) {

inst/WORDLIST

Lines changed: 54 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,92 @@
1+
Adaptor
12
AppVeyor
2-
batchtools
3+
BatchJobs
4+
Bengtsson
35
BiocParallel
46
CMD
5-
doMC
6-
doMPI
7-
doNnn
8-
dopar
9-
doParallel
10-
doSNOW
11-
foreach
7+
CMRG
8+
Ctrl
9+
DoParam
10+
DoparParam
1211
Foreach
13-
globals
1412
HPC
15-
macOS
16-
multiprocess
17-
multisession
18-
plyr
19-
pre
13+
L'Ecuyer
14+
NMF
15+
NSP
16+
ORCID
2017
Pre
18+
RJ
19+
RngFutureError
2120
SGE
2221
Slurm
22+
VignetteAuthor
23+
VignetteEngine
24+
VignetteIndexEntry
25+
VignetteKeyword
26+
VignetteTangle
27+
Vorobiev
2328
abc
2429
adaptor
25-
Adaptor
2630
batchjobs
27-
BatchJobs
28-
Bengtsson
31+
batchtools
2932
bioc
3033
bioconductor
3134
bplapply
3235
callr
3336
cran
3437
doFuture
35-
dontrun
36-
DoparParam
38+
doMC
39+
doMPI
40+
doNnn
41+
doParallel
42+
doRNG
3743
doRedis
44+
doSNOW
45+
dofuture
46+
doi
47+
dontrun
48+
dopar
3849
dorng
39-
doRNG
4050
expr
51+
fcn
52+
foreach
4153
frontends
54+
furrr
55+
futureverse
4256
getDoParName
4357
getDoParVersion
4458
getDoParWorkers
4559
glmnet
60+
globals
4661
hardcoded
4762
href
4863
https
64+
kB
65+
lapply
4966
llply
67+
lt
68+
macOS
5069
makeCluster
5170
maxSize
71+
md
72+
mtcars
73+
multiprocess
74+
multisession
5275
nbr
53-
NMF
76+
noexport
5477
nullexport
5578
num
79+
onMisuse
80+
parallelization
81+
parallelize
82+
parallelizes
83+
plyr
84+
pre
85+
pregenerating
5686
preschedule
5787
probs
88+
progressor
89+
progressr
5890
registerDoFuture
5991
registerDoMC
6092
registerDoMPI
@@ -63,6 +95,7 @@ registerDoRedis
6395
registerDoSEQ
6496
registerDoSNOW
6597
reproducibility
98+
rng
6699
rnorm
67100
rsp
68101
sd
@@ -75,35 +108,3 @@ str
75108
td
76109
th
77110
unlist
78-
VignetteAuthor
79-
VignetteEngine
80-
VignetteIndexEntry
81-
VignetteKeyword
82-
VignetteTangle
83-
Vorobiev
84-
noexport
85-
mtcars
86-
onMisuse
87-
rng
88-
DoParam
89-
RngFutureError
90-
md
91-
CMRG
92-
dofuture
93-
furrr
94-
kB
95-
NSP
96-
parallelization
97-
parallelize
98-
parallelizes
99-
pregenerating
100-
L'Ecuyer
101-
fcn
102-
lapply
103-
lt
104-
futureverse
105-
doi
106-
ORCID
107-
progressor
108-
progressr
109-
RJ

0 commit comments

Comments
 (0)