Skip to content

Commit b9e43f9

Browse files
BUG FIX: plan(batchtools_multicore) did not support 'workers' argument being a function
1 parent 979548c commit b9e43f9

File tree

5 files changed

+14
-4
lines changed

5 files changed

+14
-4
lines changed

.github/workflows/future_tests.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ jobs:
1616
fail-fast: false
1717
matrix:
1818
future:
19-
- { plan: 'future.batchtools::batchtools_local' }
19+
- { plan: 'future.batchtools::batchtools_local' }
20+
- { plan: 'future.batchtools::batchtools_multicore' }
2021
- { plan: 'future.batchtools::batchtools_interactive' }
2122

2223
env:

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
Package: future.batchtools
2-
Version: 0.12.0-9000
2+
Version: 0.12.0-9001
33
Depends:
44
R (>= 3.2.0),
55
parallelly,

NEWS.md

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

3-
* ...
3+
## Bug Fixes
4+
5+
* `plan(batchtools_multicore)` did not support `workers` argument
6+
being a function.
47

58

69
# Version 0.12.0 [2023-02-24]

R/batchtools_multicore.R

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,11 @@ batchtools_multicore <- function(expr, envir = parent.frame(),
3333
registry = list(), ...) {
3434
if (substitute) expr <- substitute(expr)
3535

36-
if (is.null(workers)) workers <- availableCores(constraints = "multicore")
36+
if (is.null(workers)) {
37+
workers <- availableCores(constraints = "multicore")
38+
} else if (is.function(workers)) {
39+
workers <- workers()
40+
}
3741
stop_if_not(length(workers) == 1L, is.numeric(workers),
3842
is.finite(workers), workers >= 1L)
3943

R/nbrOfWorkers.R

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ nbrOfWorkers.batchtools <- function(evaluator) {
1818
expr <- formals(evaluator)$workers
1919
workers <- eval(expr, enclos = baseenv())
2020
if (!is.null(workers)) {
21+
if (is.function(workers)) workers <- workers()
2122
stop_if_not(length(workers) >= 1)
2223
if (is.numeric(workers)) return(prod(workers))
2324
if (is.character(workers)) return(length(workers))
@@ -57,6 +58,7 @@ nbrOfWorkers.batchtools_multicore <- function(evaluator) {
5758
## 1. Infer from 'workers' argument
5859
expr <- formals(evaluator)$workers
5960
workers <- eval(expr, enclos = baseenv())
61+
if (is.function(workers)) workers <- workers()
6062
stop_if_not(length(workers) == 1L, is.numeric(workers), !is.na(workers), is.finite(workers), workers >= 1)
6163
workers
6264
}

0 commit comments

Comments
 (0)