@@ -165,9 +165,12 @@ print.BatchtoolsFuture <- function(x, ...) {
165165 # # batchtools specific
166166 reg <- x $ config $ reg
167167
168- # # Type of batchtools future
169- printf(" batchtools cluster functions: %s\n " ,
170- sQuote(reg $ cluster.functions $ name ))
168+ if (inherits(reg , " Registry" )) {
169+ printf(" batchtools cluster functions: %s\n " ,
170+ sQuote(reg $ cluster.functions $ name ))
171+ } else {
172+ printf(" batchtools cluster functions: N/A\n " )
173+ }
171174
172175 # # Ask for status once
173176 status <- status(x )
@@ -180,10 +183,14 @@ print.BatchtoolsFuture <- function(x, ...) {
180183 printf(" batchtools %s: Not found (happens when finished and deleted)\n " ,
181184 class(reg ))
182185 } else {
183- printf(" batchtools Registry:\n " )
184- printf(" File dir exists: %s\n " , file_test(" -d" , reg $ file.dir ))
185- printf(" Work dir exists: %s\n " , file_test(" -d" , reg $ work.dir ))
186- try(print(reg ))
186+ if (inherits(reg , " Registry" )) {
187+ printf(" batchtools Registry:\n " )
188+ printf(" File dir exists: %s\n " , file_test(" -d" , reg $ file.dir ))
189+ printf(" Work dir exists: %s\n " , file_test(" -d" , reg $ work.dir ))
190+ try(print(reg ))
191+ } else {
192+ printf(" batchtools Registry: N/A\n " )
193+ }
187194 }
188195
189196 invisible (x )
@@ -286,6 +293,7 @@ loggedError.BatchtoolsFuture <- function(future, ...) {
286293
287294 config <- future $ config
288295 reg <- config $ reg
296+ if (! inherits(reg , " Registry" )) return (NULL )
289297 jobid <- config $ jobid
290298 res <- getErrorMessages(reg = reg , ids = jobid ) # ## CHECKED
291299 msg <- res $ message
@@ -310,6 +318,7 @@ loggedOutput.BatchtoolsFuture <- function(future, ...) {
310318
311319 config <- future $ config
312320 reg <- config $ reg
321+ if (! inherits(reg , " Registry" )) return (NULL )
313322 jobid <- config $ jobid
314323 getLog(id = jobid , reg = reg )
315324} # loggedOutput()
@@ -400,7 +409,29 @@ run.BatchtoolsFuture <- function(future, ...) {
400409 # # Always evaluate in local environment
401410 expr <- substitute(local(expr ), list (expr = expr ))
402411
412+ # # (i) Create batchtools registry
403413 reg <- future $ config $ reg
414+ stop_if_not(is.null(reg ) || inherits(reg , " Registry" ))
415+ if (is.null(reg )) {
416+ if (debug ) mprint(" - Creating batchtools registry" )
417+ config <- future $ config
418+ stop_if_not(is.list(config ))
419+
420+ # # Create batchtools registry
421+ reg <- temp_registry(
422+ label = future $ label ,
423+ conf.file = config $ conf.file ,
424+ cluster.functions = config $ cluster.functions ,
425+ config = config $ registry
426+ )
427+ if (debug ) mprint(reg )
428+ future $ config $ reg <- reg
429+
430+ # # Register finalizer?
431+ if (config $ finalize ) future <- add_finalizer(future )
432+
433+ config <- NULL
434+ }
404435 stop_if_not(inherits(reg , " Registry" ))
405436
406437 # # (ii) Attach packages that needs to be attached
@@ -522,6 +553,7 @@ await.BatchtoolsFuture <- function(future, cleanup = TRUE,
522553 expr <- future $ expr
523554 config <- future $ config
524555 reg <- config $ reg
556+ stop_if_not(inherits(reg , " Registry" ))
525557 jobid <- config $ jobid
526558
527559 mdebug(" batchtools::waitForJobs() ..." )
@@ -641,6 +673,10 @@ delete.BatchtoolsFuture <- function(future,
641673 # # Identify registry
642674 config <- future $ config
643675 reg <- config $ reg
676+
677+ # # Trying to delete a non-launched batchtools future?
678+ if (! inherits(reg , " Registry" )) return (invisible (TRUE ))
679+
644680 path <- reg $ file.dir
645681
646682 # # Already deleted?
0 commit comments