@@ -59,14 +59,14 @@ BatchtoolsFuture <- function(expr = NULL, envir = parent.frame(),
5959 stop_if_not(is.list(cluster.functions ))
6060 }
6161
62+ if (is.function(workers )) workers <- workers()
6263 if (! is.null(workers )) {
6364 stop_if_not(length(workers ) > = 1 )
6465 if (is.numeric(workers )) {
6566 stop_if_not(! anyNA(workers ), all(workers > = 1 ))
66- } else if (is.character(workers )) {
6767 } else {
68- stop_if_not (" Argument 'workers' should be either numeric or character : " ,
69- mode(workers ))
68+ stop (" Argument 'workers' should be either a numeric or a function : " ,
69+ mode(workers ))
7070 }
7171 }
7272
@@ -321,8 +321,6 @@ run.BatchtoolsFuture <- function(future, ...) {
321321 stop(sprintf(" A future ('%s') can only be launched once." , label ))
322322 }
323323
324- mdebug <- import_future(" mdebug" )
325-
326324 # # Assert that the process that created the future is
327325 # # also the one that evaluates/resolves/queries it.
328326 assertOwner <- import_future(" assertOwner" )
@@ -350,7 +348,7 @@ run.BatchtoolsFuture <- function(future, ...) {
350348 # # (ii) Attach packages that needs to be attached
351349 packages <- future $ packages
352350 if (length(packages ) > 0 ) {
353- mdebug (" Attaching %d packages (%s) ..." ,
351+ mdebugf (" Attaching %d packages (%s) ..." ,
354352 length(packages ), hpaste(sQuote(packages )))
355353
356354 # # Record which packages in 'pkgs' that are loaded and
@@ -364,7 +362,7 @@ run.BatchtoolsFuture <- function(future, ...) {
364362 reg $ packages <- packages
365363 saveRegistry(reg = reg )
366364
367- mdebug (" Attaching %d packages (%s) ... DONE" ,
365+ mdebugf (" Attaching %d packages (%s) ... DONE" ,
368366 length(packages ), hpaste(sQuote(packages )))
369367 }
370368 # # Not needed anymore
@@ -388,7 +386,7 @@ run.BatchtoolsFuture <- function(future, ...) {
388386
389387 # # 2. Update
390388 future $ config $ jobid <- jobid
391- mdebug (" Created %s future #%d" , class(future )[1 ], jobid $ job.id )
389+ mdebugf (" Created %s future #%d" , class(future )[1 ], jobid $ job.id )
392390
393391 # # WORKAROUND: (For multicore and macOS only)
394392 if (reg $ cluster.functions $ name == " Multicore" ) {
@@ -419,7 +417,7 @@ run.BatchtoolsFuture <- function(future, ...) {
419417
420418 batchtools :: submitJobs(reg = reg , ids = jobid , resources = resources )
421419
422- mdebug (" Launched future #%d" , jobid $ job.id )
420+ mdebugf (" Launched future #%d" , jobid $ job.id )
423421
424422 invisible (future )
425423} # # run()
@@ -458,7 +456,6 @@ await.BatchtoolsFuture <- function(future, cleanup = TRUE,
458456 1.0 ),
459457 alpha = getOption(" future.wait.alpha" , 1.01 ),
460458 ... ) {
461- mdebug <- import_future(" mdebug" )
462459 stop_if_not(is.finite(timeout ), timeout > = 0 )
463460 stop_if_not(is.finite(alpha ), alpha > 0 )
464461
@@ -480,9 +477,9 @@ await.BatchtoolsFuture <- function(future, cleanup = TRUE,
480477
481478 res <- waitForJobs(ids = jobid , timeout = timeout , sleep = sleep_fcn ,
482479 stop.on.error = FALSE , reg = reg )
483- mdebug (" - batchtools::waitForJobs(): %s" , res )
480+ mdebugf (" - batchtools::waitForJobs(): %s" , res )
484481 stat <- status(future )
485- mdebug (" - status(): %s" , paste(sQuote(stat ), collapse = " , " ))
482+ mdebugf (" - status(): %s" , paste(sQuote(stat ), collapse = " , " ))
486483 mdebug(" batchtools::waitForJobs() ... done" )
487484
488485 finished <- is_na(stat ) || any(c(" finished" , " error" , " expired" ) %in% stat )
@@ -515,11 +512,11 @@ await.BatchtoolsFuture <- function(future, cleanup = TRUE,
515512 output <- loggedOutput(future )
516513 hint <- unlist(strsplit(output , split = " \n " , fixed = TRUE ))
517514 hint <- hint [nzchar(hint )]
518- hint <- tail(hint , n = 6L )
515+ hint <- tail(hint , n = getOption( " future.batchtools.expiration.tail " , 48L ) )
519516 if (length(hint ) > 0 ) {
520517 hint <- paste(hint , collapse = " \n " )
521- msg <- sprintf( " %s . The last few lines of the logged output:\n %s " ,
522- msg , hint )
518+ msg <- paste( msg , " . The last few lines of the logged output:\n " ,
519+ hint , sep = " " )
523520 } else {
524521 msg <- sprintf(" %s. No logged output exist." , msg )
525522 }
@@ -576,8 +573,6 @@ delete.BatchtoolsFuture <- function(future,
576573 delta = getOption(" future.wait.interval" , 1.0 ),
577574 alpha = getOption(" future.wait.alpha" , 1.01 ),
578575 ... ) {
579- mdebug <- import_future(" mdebug" )
580-
581576 onRunning <- match.arg(onRunning )
582577 onMissing <- match.arg(onMissing )
583578 onFailure <- match.arg(onFailure )
@@ -593,7 +588,7 @@ delete.BatchtoolsFuture <- function(future,
593588 if (is.null(path ) || ! file_test(" -d" , path )) {
594589 if (onMissing %in% c(" warning" , " error" )) {
595590 msg <- sprintf(" Cannot remove batchtools registry, because directory does not exist: %s" , sQuote(path )) # nolint
596- mdebug (" delete(): %s" , msg )
591+ mdebugf (" delete(): %s" , msg )
597592 if (onMissing == " warning" ) {
598593 warning(msg )
599594 } else if (onMissing == " error" ) {
@@ -611,7 +606,7 @@ delete.BatchtoolsFuture <- function(future,
611606 label <- future $ label
612607 if (is.null(label )) label <- " <none>"
613608 msg <- sprintf(" Will not remove batchtools registry, because is appears to hold a non-resolved future (%s; state = %s; batchtools status = %s): %s" , sQuote(label ), sQuote(future $ state ), paste(sQuote(status ), collapse = " , " ), sQuote(path )) # nolint
614- mdebug (" delete(): %s" , msg )
609+ mdebugf (" delete(): %s" , msg )
615610 if (onRunning == " warning" ) {
616611 warning(msg )
617612 return (invisible (TRUE ))
@@ -627,24 +622,31 @@ delete.BatchtoolsFuture <- function(future,
627622
628623 # # To simplify post mortem troubleshooting in non-interactive sessions,
629624 # # should the batchtools registry files be removed or not?
630- mdebug (" delete(): Option 'future.delete = %s" ,
625+ mdebugf (" delete(): Option 'future.delete = %s" ,
631626 sQuote(getOption(" future.delete" , " <NULL>" )))
632627 if (! getOption(" future.delete" , interactive())) {
633628 status <- status(future )
634629 res <- future $ result
635630 if (inherits(res , " FutureResult" )) {
636631 if (result_has_errors(res )) status <- unique(c(" error" , status ))
637632 }
638- mdebug (" delete(): status(<future>) = %s" ,
633+ mdebugf (" delete(): status(<future>) = %s" ,
639634 paste(sQuote(status ), collapse = " , " ))
640635 if (any(c(" error" , " expired" ) %in% status )) {
641636 msg <- sprintf(" Will not remove batchtools registry, because the status of the batchtools was %s and option 'future.delete' is FALSE or running in an interactive session: %s" , paste(sQuote(status ), collapse = " , " ), sQuote(path )) # nolint
642- mdebug (" delete(): %s" , msg )
637+ mdebugf (" delete(): %s" , msg )
643638 warning(msg )
644639 return (invisible (FALSE ))
645640 }
646641 }
647642
643+ # # Have user disabled deletions?
644+ if (! getOption(" future.delete" , TRUE )) {
645+ msg <- sprintf(" Option 'future.delete' is FALSE - will not delete batchtools registry: %s" , sQuote(path ))
646+ mdebugf(" delete(): %s" , msg )
647+ return (invisible (FALSE ))
648+ }
649+
648650 # # Control batchtools info output
649651 oopts <- options(batchtools.verbose = debug )
650652 on.exit(options(oopts ))
@@ -664,7 +666,7 @@ delete.BatchtoolsFuture <- function(future,
664666 if (file_test(" -d" , path )) {
665667 if (onFailure %in% c(" warning" , " error" )) {
666668 msg <- sprintf(" Failed to remove batchtools registry: %s" , sQuote(path ))
667- mdebug (" delete(): %s" , msg )
669+ mdebugf (" delete(): %s" , msg )
668670 if (onMissing == " warning" ) {
669671 warning(msg )
670672 } else if (onMissing == " error" ) {
@@ -674,7 +676,7 @@ delete.BatchtoolsFuture <- function(future,
674676 return (invisible (FALSE ))
675677 }
676678
677- mdebug (" delete(): batchtools registry deleted: %s" , sQuote(path ))
679+ mdebugf (" delete(): batchtools registry deleted: %s" , sQuote(path ))
678680
679681 invisible (TRUE )
680682} # delete()
0 commit comments