44# '
55# ' @param workers (optional) The maximum number of workers the batchtools
66# ' backend may use at any time. Interactive and "local" backends can only
7- # ' process one future at the time (`workers = 1L `), whereas HPC backends,
7+ # ' process one future at the time (`workers = 1 `), whereas HPC backends,
88# ' where futures are resolved via separate jobs on a scheduler, can have
9- # ' multiple workers. In the latter, the default is `workers = NULL`, which
10- # ' will resolve to
11- # ' \code{getOption("\link{future.batchtools.workers}")}.
12- # ' If neither are specified, then the default is `100`.
9+ # ' multiple workers. In the latter, the default is `workers = NULL`, which
10+ # ' will resolve to \code{getOption("\link{future.batchtools.workers}", 100)}.
1311# '
1412# ' @param finalize If TRUE, a future's \pkg{batchtools}
1513# ' \link[batchtools:makeRegistry]{Registry} is automatically deleted when
4240# ' @keywords internal
4341# ' @export
4442BatchtoolsFutureBackend <- function (
45- workers = NULL , resources = list (),
43+ workers = 1L , resources = list (),
4644 finalize = getOption(" future.finalize" , TRUE ),
4745 cluster.functions = NULL ,
4846 registry = list (),
@@ -52,23 +50,12 @@ BatchtoolsFutureBackend <- function(
5250 assert_no_positional_args_but_first()
5351
5452 if (is.function(workers )) workers <- workers()
55- if (is.null(workers )) {
56- workers <- getOption(" future.batchtools.workers" , default = 100 )
57- stop_if_not(
58- is.numeric(workers ),
59- length(workers ) == 1L ,
60- ! is.na(workers ), workers > = 1
61- )
53+ if (is.numeric(workers )) {
54+ stop_if_not(length(workers ) == 1L , ! is.na(workers ), workers > = 1 )
55+ } else if (is.character(workers )) {
56+ stop_if_not(length(workers ) > = 1L , ! anyNA(workers ), all(nzchar(workers )))
6257 } else {
63- stop_if_not(length(workers ) > = 1L )
64- if (is.numeric(workers )) {
65- stop_if_not(length(workers ) == 1L , ! is.na(workers ), workers > = 1 )
66- } else if (is.character(workers )) {
67- stop_if_not(length(workers ) > = 0L , ! anyNA(workers ))
68- } else {
69- stop(" Argument 'workers' should be either a numeric or a function: " ,
70- mode(workers ))
71- }
58+ stop(" Argument 'workers' should be either a numeric, a character vector, or a function: " , mode(workers ))
7259 }
7360
7461 if (! is.null(cluster.functions )) {
0 commit comments