Skip to content

Commit 3035041

Browse files
TESTS: Add a batchtools configuration R script for testing batchtools_custom() [#10]
1 parent 65d8a90 commit 3035041

File tree

3 files changed

+31
-16
lines changed

3 files changed

+31
-16
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
cluster.functions <- batchtools::makeClusterFunctionsInteractive(external = TRUE)

tests/batchtools_custom.R

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,22 @@ library("listenv")
44

55
message("*** batchtools_custom() ...")
66

7-
cf <- makeClusterFunctionsInteractive(external = TRUE)
8-
str(cf)
7+
message("*** batchtools_custom() w/ 'conf.file' on R_BATCHTOOLS_SEARCH_PATH")
8+
9+
f <- batchtools_custom({
10+
42L
11+
})
12+
print(f)
13+
stopifnot(inherits(f, "BatchtoolsFuture"))
14+
v <- value(f)
15+
print(v)
16+
stopifnot(v == 42L)
917

1018

11-
message("*** batchtools_custom() ...")
19+
message("*** batchtools_custom() w/ 'cluster.functions' without globals")
1220

13-
message("*** batchtools_custom() without globals")
21+
cf <- makeClusterFunctionsInteractive(external = TRUE)
22+
str(cf)
1423

1524
f <- batchtools_custom({
1625
42L
@@ -27,7 +36,7 @@ print(y)
2736
stopifnot(y == 42L)
2837

2938

30-
message("*** batchtools_custom() with globals")
39+
message("*** batchtools_custom() w/ 'cluster.functions' with globals")
3140
## A global variable
3241
a <- 0
3342
f <- batchtools_custom({
@@ -50,7 +59,7 @@ print(v)
5059
stopifnot(v == 0)
5160

5261

53-
message("*** batchtools_custom() with globals (tricky)")
62+
message("*** batchtools_custom() w/ 'cluster.functions' with globals (tricky)")
5463
x <- listenv()
5564
for (ii in 1:2) {
5665
x[[ii]] <- batchtools_custom({ ii }, globals = TRUE, cluster.functions = cf)
@@ -59,7 +68,7 @@ v <- unlist(values(x))
5968
stopifnot(all(v == 1:2)) ## Make sure globals are frozen
6069

6170

62-
message("*** batchtools_custom() and errors")
71+
message("*** batchtools_custom() w/ 'cluster.functions' and errors")
6372
f <- batchtools_custom({
6473
stop("Whoops!")
6574
1

tests/incl/start,load-only.R

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,20 @@ oplan <- future::plan()
1313
options(future.batchtools.workers = NULL)
1414
Sys.unsetenv("R_FUTURE_BATCHTOOLS_WORKERS")
1515

16+
path <- Sys.getenv("R_BATCHTOOLS_SEARCH_PATH")
17+
if (!nzchar(path)) {
18+
path <- system.file(package = "future.batchtools",
19+
"templates-for-R_CMD_check", mustWork = TRUE)
20+
Sys.setenv(R_BATCHTOOLS_SEARCH_PATH = path)
21+
} else {
22+
warning("Using a non-standard R_BATCHTOOLS_SEARCH_PATH while testing: ",
23+
sQuote(path))
24+
if (!file_test("-d", path)) {
25+
stop("R_BATCHTOOLS_SEARCH_PATH specifies a non-existing folder: ",
26+
sQuote(path))
27+
}
28+
}
29+
1630
## Use local batchtools futures by default
1731
future::plan(future.batchtools::batchtools_local)
1832

@@ -33,15 +47,6 @@ all_strategies <- local({
3347
## When testing for instance 'batchtools_sge', look for a customize
3448
## template file, e.g. R_BATCHTOOLS_SEARCH_PATH/batchtools.sge.tmpl
3549
if (length(strategies) > 0L) {
36-
path <- Sys.getenv("R_BATCHTOOLS_SEARCH_PATH")
37-
if (!nzchar(path)) {
38-
path <- system.file(package = "future.batchtools",
39-
"templates-for-R_CMD_check", mustWork = TRUE)
40-
Sys.setenv(R_BATCHTOOLS_SEARCH_PATH = path)
41-
} else if (!file_test("-d", path)) {
42-
warning("R_BATCHTOOLS_SEARCH_PATH specifies a non-existing folder: ",
43-
sQuote(path))
44-
}
4550
## If there is a custom R_BATCHTOOLS_SEARCH_PATH/setup.R' file, run it
4651
pathname <- file.path(path, "setup.R")
4752
if (file_test("-f", pathname)) source(pathname, local = envir)

0 commit comments

Comments
 (0)