Skip to content

Commit 65d8a90

Browse files
batchtools_custom() and BatchtoolsFuture gained argument 'conf.file' [#10]
1 parent 741d969 commit 65d8a90

File tree

7 files changed

+72
-37
lines changed

7 files changed

+72
-37
lines changed

NAMESPACE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ export(status)
3030
importFrom(batchtools,batchExport)
3131
importFrom(batchtools,batchMap)
3232
importFrom(batchtools,clearRegistry)
33+
importFrom(batchtools,findConfFile)
3334
importFrom(batchtools,findTemplateFile)
3435
importFrom(batchtools,getErrorMessages)
3536
importFrom(batchtools,getLog)

NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ NEW FEATURES:
3636
* The default location of the '.future' folder can be controlled by R option
3737
'future.cache.path' or environment variable 'R_FUTURE_CACHE_PATH'.
3838

39+
* batchtools_custom() and BatchtoolsFuture gained argument 'conf.file'.
40+
3941
DOCUMENTATION:
4042

4143
* Add help("future.batchtools.options") which descriptions R options and

R/BatchtoolsFuture-class.R

Lines changed: 31 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,6 @@
1919
#' @param label (optional) Label of the future (where applicable, becomes the
2020
#' job name for most job schedulers).
2121
#'
22-
#' @param conf A batchtools configuration environment.
23-
#'
24-
#' @param cluster.functions A batchtools
25-
#' [ClusterFunctions][batchtools::ClusterFunctions] object.
26-
#'
27-
#' @param registry (optional) A named list of settings to control the setup
28-
#' of the batchtools registry.
29-
#'
3022
#' @param resources (optional) A named list passed to the batchtools template
3123
#' (available as variable `resources`).
3224
#'
@@ -42,6 +34,14 @@
4234
#' @param finalize If TRUE, any underlying registries are
4335
#' deleted when this object is garbage collected, otherwise not.
4436
#'
37+
#' @param conf.file (optional) A batchtools configuration file.
38+
#'
39+
#' @param cluster.functions (optional) A batchtools
40+
#' [ClusterFunctions][batchtools::ClusterFunctions] object.
41+
#'
42+
#' @param registry (optional) A named list of settings to control the setup
43+
#' of the batchtools registry.
44+
#'
4545
#' @param \ldots Additional arguments passed to [future::Future()].
4646
#'
4747
#' @return A BatchtoolsFuture object
@@ -53,19 +53,32 @@
5353
BatchtoolsFuture <- function(expr = NULL, envir = parent.frame(),
5454
substitute = TRUE,
5555
globals = TRUE, packages = NULL,
56-
label = NULL, cluster.functions = NULL,
57-
registry = list(),
58-
resources = list(), workers = NULL,
56+
label = NULL,
57+
resources = list(),
58+
workers = NULL,
5959
finalize = getOption("future.finalize", TRUE),
60+
conf.file = findConfFile(),
61+
cluster.functions = NULL,
62+
registry = list(),
6063
...) {
6164
if (substitute) expr <- substitute(expr)
6265

6366
if (!is.null(label)) label <- as.character(label)
6467

6568
if (!is.null(cluster.functions)) {
6669
stop_if_not(is.list(cluster.functions))
70+
stop_if_not(inherits(cluster.functions, "ClusterFunctions"))
71+
} else if (missing(conf.file)) {
72+
## BACKWARD COMPATILITY: Only when calling BatchtoolsFuture() directly
73+
cluster.functions <- makeClusterFunctionsInteractive(external = FALSE)
74+
} else {
75+
## If 'cluster.functions' is not specified, then 'conf.file' must
76+
## exist
77+
if (!file_test("-f", conf.file)) {
78+
stop("No such batchtools configuration file: ", sQuote(conf.file))
79+
}
6780
}
68-
81+
6982
if (is.function(workers)) workers <- workers()
7083
if (!is.null(workers)) {
7184
stop_if_not(length(workers) >= 1)
@@ -96,10 +109,12 @@ BatchtoolsFuture <- function(expr = NULL, envir = parent.frame(),
96109
future$packages <- unique(c(packages, gp$packages))
97110

98111
## Create batchtools registry
99-
reg <- temp_registry(label = future$label, config = registry)
100-
if (!is.null(cluster.functions)) { ### FIXME
101-
reg$cluster.functions <- cluster.functions
102-
}
112+
reg <- temp_registry(
113+
label = future$label,
114+
conf.file = conf.file,
115+
cluster.functions = cluster.functions,
116+
config = registry
117+
)
103118
debug <- getOption("future.debug", FALSE)
104119
if (debug) mprint(reg)
105120

R/batchtools_custom.R

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
#'
33
#' @inheritParams BatchtoolsFuture
44
#'
5+
#' @param conf.file (character) A batchtools configuration file as for
6+
#' instance returned by [batchtools::findConfFile()].
7+
#'
58
#' @param cluster.functions A
69
#' [ClusterFunctions][batchtools::ClusterFunctions] object.
710
#'
@@ -12,20 +15,25 @@
1215
#' @example incl/batchtools_custom.R
1316
#'
1417
#' @export
18+
#' @importFrom batchtools findConfFile
1519
#' @importFrom utils file_test
1620
batchtools_custom <- function(expr, envir = parent.frame(), substitute = TRUE,
17-
globals = TRUE, label = NULL,
18-
cluster.functions,
19-
resources = list(), workers = NULL,
20-
registry = list(), ...) {
21+
globals = TRUE,
22+
label = NULL,
23+
resources = list(),
24+
workers = NULL,
25+
conf.file = findConfFile(),
26+
cluster.functions = NULL,
27+
registry = list(),
28+
...) {
2129
if (substitute) expr <- substitute(expr)
22-
stop_if_not(inherits(cluster.functions, "ClusterFunctions"))
2330

2431
future <- BatchtoolsFuture(expr = expr, envir = envir, substitute = FALSE,
2532
globals = globals,
2633
label = label,
27-
cluster.functions = cluster.functions,
2834
resources = resources,
35+
conf.file = conf.file,
36+
cluster.functions = cluster.functions,
2937
workers = workers,
3038
registry = registry,
3139
...)

R/temp_registry.R

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ temp_registry <- local({
33
## All known batchtools registries
44
regs <- new.env()
55

6-
make_registry <- function(config = list(), ...) {
7-
## Temporarily disable batchtools output?
6+
make_registry <- function(cluster.functions = NULL, config = list(), ...) {
7+
## Temporarily disable batchtools output?
88
## (i.e. messages and progress bars)
99
debug <- getOption("future.debug", FALSE)
1010
batchtools_output <- getOption("future.batchtools.output", debug)
@@ -20,6 +20,10 @@ temp_registry <- local({
2020

2121
reg <- makeRegistry(work.dir = work.dir, ...)
2222

23+
if (!is.null(cluster.functions)) { ### FIXME
24+
reg$cluster.functions <- cluster.functions
25+
}
26+
2327
## Post-tweak the batchtools registry?
2428
## This avoids having to set up a custom batchtools 'conf.file' etc.
2529
if (length(config) > 0L) {

man/BatchtoolsFuture.Rd

Lines changed: 10 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/batchtools_custom.Rd

Lines changed: 8 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)