Skip to content

Commit 0e5cc95

Browse files
Implement BatchtoolsInteractiveFutureBackend
1 parent 4d28739 commit 0e5cc95

6 files changed

+49
-27
lines changed

DESCRIPTION

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
Package: future.batchtools
2-
Version: 0.12.1-9102
2+
Version: 0.12.1-9103
33
Depends:
44
R (>= 3.2.0),
55
parallelly,

NAMESPACE

+1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ export(BatchtoolsFuture)
3535
export(BatchtoolsFutureBackend)
3636
export(BatchtoolsFutureError)
3737
export(BatchtoolsInteractiveFuture)
38+
export(BatchtoolsInteractiveFutureBackend)
3839
export(BatchtoolsLocalFuture)
3940
export(BatchtoolsLocalFutureBackend)
4041
export(BatchtoolsLsfFuture)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#' @rdname BatchtoolsFutureBackend
2+
#' @importFrom batchtools makeClusterFunctionsInteractive
3+
#' @export
4+
BatchtoolsInteractiveFutureBackend <- function(..., cluster.functions = NULL) {
5+
cluster.functions <- makeClusterFunctionsInteractive(external = FALSE)
6+
core <- BatchtoolsFutureBackend(
7+
...,
8+
cluster.functions = cluster.functions
9+
)
10+
11+
core[["futureClasses"]] <- c("BatchtoolsInteractiveFuture", core[["futureClasses"]])
12+
core <- structure(core, class = c("BatchtoolsInteractiveFutureBackend", "BatchtoolsSequentialFutureBackend", setdiff(class(core), "MultiprocessFutureBackend")))
13+
core
14+
}
15+
16+
17+
#' @inheritParams BatchtoolsUniprocessFuture
18+
#'
19+
#' @importFrom batchtools makeClusterFunctionsInteractive
20+
#' @export
21+
batchtools_interactive <- function(..., envir = parent.frame()) {
22+
stop("INTERNAL ERROR: The future.batchtools::batchtools_sequential() function implements the FutureBackend and should never be called directly")
23+
}
24+
class(batchtools_interactive) <- c(
25+
"batchtools_interactive", "batchtools_uniprocess", "batchtools",
26+
"uniprocess", "future", "function"
27+
)
28+
attr(batchtools_interactive, "tweakable") <- c("finalize")
29+
attr(batchtools_interactive, "untweakable") <- c("workers")
30+
attr(batchtools_interactive, "factory") <- BatchtoolsInteractiveFutureBackend
31+

R/batchtools_interactive.R

-16
This file was deleted.

inst/testme/test-batchtools_interactive.R

+12-10
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
library(future.batchtools)
22
library(listenv)
33

4-
message("*** batchtools_interactive() ...")
4+
message("*** 'batchtools_interactive' ...")
55

6-
message("*** batchtools_interactive() without globals")
6+
plan(batchtools_interactive)
77

8-
f <- batchtools_interactive({
8+
message("*** 'batchtools_interactive' without globals")
9+
10+
f <- future({
911
42L
1012
})
1113
stopifnot(inherits(f, "BatchtoolsFuture"))
@@ -20,10 +22,10 @@ print(y)
2022
stopifnot(y == 42L)
2123

2224

23-
message("*** batchtools_interactive() with globals")
25+
message("*** 'batchtools_interactive' with globals")
2426
## A global variable
2527
a <- 0
26-
f <- batchtools_interactive({
28+
f <- future({
2729
b <- 3
2830
c <- 2
2931
a * b * c
@@ -42,15 +44,15 @@ print(v)
4244
stopifnot(v == 0)
4345

4446

45-
message("*** batchtools_interactive() with globals (tricky)")
47+
message("*** 'batchtools_interactive' with globals (tricky)")
4648
x <- listenv()
47-
for (ii in 1:2) x[[ii]] <- batchtools_interactive({ ii }, globals = TRUE)
49+
for (ii in 1:2) x[[ii]] <- future({ ii }, globals = TRUE)
4850
v <- unlist(value(x))
4951
stopifnot(all(v == 1:2)) ## Make sure globals are frozen
5052

5153

52-
message("*** batchtools_interactive() and errors")
53-
f <- batchtools_interactive({
54+
message("*** 'batchtools_interactive' and errors")
55+
f <- future({
5456
stop("Whoops!")
5557
1
5658
})
@@ -67,5 +69,5 @@ res <- try(value(f), silent = TRUE)
6769
print(res)
6870
stopifnot(inherits(res, "try-error"))
6971

70-
message("*** batchtools_interactive() ... DONE")
72+
message("*** 'batchtools_interactive' ... DONE")
7173

man/BatchtoolsFutureBackend.Rd

+4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)