R Under development (unstable) (2025-06-05 r88281 ucrt) -- "Unsuffered Consequences" Copyright (C) 2025 The R Foundation for Statistical Computing Platform: x86_64-w64-mingw32/x64 R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details. R is a collaborative project with many contributors. Type 'contributors()' for more information and 'citation()' on how to cite R or R packages in publications. Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for an HTML browser interface to help. Type 'q()' to quit R. > source("incl/start.R") Loading required package: parallelly Loading required package: future > library("listenv") > > message("*** batchtools_local() ...") *** batchtools_local() ... > > message("*** batchtools_local() without globals") *** batchtools_local() without globals > > f <- batchtools_local({ + 42L + }) [04:37:21.557] Launched future #1 > stopifnot(inherits(f, "BatchtoolsFuture")) > > ## Check whether a batchtools_local future is resolved > ## or not will force evaluation > print(is_resolved <- resolved(f)) [1] TRUE > stopifnot(is_resolved) > > y <- value(f) > print(y) [1] 42 > stopifnot(y == 42L) > > > message("*** batchtools_local() with globals") *** batchtools_local() with globals > ## A global variable > a <- 0 > f <- batchtools_local({ + b <- 3 + c <- 2 + a * b * c + }) [04:37:23.152] Launched future #1 > > ## Although 'f' is a batchtools_local future and therefore > ## resolved/evaluates the future expression only > ## when the value is requested, any global variables > ## identified in the expression (here 'a') are > ## "frozen" at the time point when the future is > ## created. Because of this, 'a' preserved the > ## zero value although we reassign it below > a <- 7 ## Make sure globals are frozen > v <- value(f) > print(v) [1] 0 > stopifnot(v == 0) > > > message("*** batchtools_local() with globals (tricky)") *** batchtools_local() with globals (tricky) > x <- listenv() > for (ii in 1:2) x[[ii]] <- batchtools_local({ ii }, globals = TRUE) [04:37:24.979] Launched future #1 [04:37:26.103] Launched future #1 > v <- unlist(value(x)) > stopifnot(all(v == 1:2)) ## Make sure globals are frozen > > > message("*** batchtools_local() and errors") *** batchtools_local() and errors > f <- batchtools_local({ + stop("Whoops!") + 1 + }) [04:37:27.635] Launched future #1 > v <- value(f, signal = FALSE) Warning in delete.BatchtoolsFuture(future) : Will not remove batchtools registry, because the status of the batchtools was 'error', 'defined', 'finished', 'started', 'submitted' and option 'future.delete' is FALSE or running in an interactive session: 'D:/temp/2025_06_06_04_35_16_24916/RtmpimuSmu/.future/20250606_043719-imuSmu/batchtools_1439723328' > print(v) > stopifnot(inherits(v, "simpleError")) > > res <- try({ v <- value(f) }, silent = TRUE) > print(res) [1] "Error in eval(quote({ : Whoops!\n" attr(,"class") [1] "try-error" attr(,"condition") > stopifnot(inherits(res, "try-error")) > > ## Error is repeated > res <- try(value(f), silent = TRUE) > print(res) [1] "Error in eval(quote({ : Whoops!\n" attr(,"class") [1] "try-error" attr(,"condition") > stopifnot(inherits(res, "try-error")) > > message("*** batchtools_local() ... DONE") *** batchtools_local() ... DONE > > source("incl/end.R") > > proc.time() user system elapsed 1.62 0.48 9.75 Warning message: In delete.BatchtoolsFuture(f, onRunning = "skip", onMissing = "ignore", : Will not remove batchtools registry, because the status of the batchtools was 'error', 'defined', 'finished', 'started', 'submitted' and option 'future.delete' is FALSE or running in an interactive session: 'D:/temp/2025_06_06_04_35_16_24916/RtmpimuSmu/.future/20250606_043719-imuSmu/batchtools_1439723328'