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") > > plan(batchtools_local) > > ## CRAN processing times: > ## On Windows 32-bit, don't run these tests on batchtools > if (!fullTest && isWin32) plan(sequential) > > message("*** Tricky use cases related to globals ...") *** Tricky use cases related to globals ... > > message("- Globals with the same name as 'base' objects ...") - Globals with the same name as 'base' objects ... > > ## 'col' is masked by 'base::col' (Issue #55) > col <- 3 > x %<-% { stopifnot(is.numeric(col)); col } [04:39:07.696] Launched future #1 > print(x) [1] 3 > stopifnot(x == col) > > ## https://github.com/mllg/batchtools/issues/88 > message("- Globals that don't necessarily map to filenames ...") - Globals that don't necessarily map to filenames ... > .a <- 42L > x %<-% { .a } [04:39:09.583] Launched future #1 > print(x) [1] 42 > stopifnot(x == .a) > > `$foo` <- 42L > x %<-% { `$foo` } [04:39:10.991] Launched future #1 > print(x) [1] 42 > stopifnot(x == `$foo`) > > > message("- flapply(x, FUN = base::vector, ...) ...") - flapply(x, FUN = base::vector, ...) ... > > flapply <- function(x, FUN, ...) { + res <- listenv() + for (ii in seq_along(x)) { + res[[ii]] %<-% FUN(x[[ii]], ...) + } + names(res) <- names(x) + + ## Make sure 'x', 'FUN' and 'ii' are truly + ## exported to the future environment + rm(list = c("x", "FUN", "ii")) + + as.list(res) + } > > x <- list(a = "integer", c = "character", c = "list") > str(list(x = x)) List of 1 $ x:List of 3 ..$ a: chr "integer" ..$ c: chr "character" ..$ c: chr "list" > > y0 <- lapply(x, FUN = base::vector, length = 2L) > str(list(y0 = y0)) List of 1 $ y0:List of 3 ..$ a: int [1:2] 0 0 ..$ c: chr [1:2] "" "" ..$ c:List of 2 .. ..$ : NULL .. ..$ : NULL > > y <- flapply(x, FUN = base::vector, length = 2L) [04:39:12.711] Launched future #1 [04:39:14.037] Launched future #1 [04:39:15.466] Launched future #1 > str(list(y = y)) List of 1 $ y:List of 3 ..$ a: int [1:2] 0 0 ..$ c: chr [1:2] "" "" ..$ c:List of 2 .. ..$ : NULL .. ..$ : NULL > stopifnot(identical(y, y0)) > > > message("- flapply(x, FUN = future:::hpaste, ...) ...") - flapply(x, FUN = future:::hpaste, ...) ... > > x <- list(a = c("hello", b = 1:100)) > str(list(x = x)) List of 1 $ x:List of 1 ..$ a: Named chr [1:101] "hello" "1" "2" "3" ... .. ..- attr(*, "names")= chr [1:101] "" "b1" "b2" "b3" ... > > y0 <- lapply(x, FUN = future:::hpaste, collapse = "; ", maxHead = 3L) > str(list(y0 = y0)) List of 1 $ y0:List of 1 ..$ a: chr "hello; 1; 2; ...; 100" > > y <- flapply(x, FUN = future:::hpaste, collapse = "; ", maxHead = 3L) [04:39:15.842] Attaching 1 packages ('future') ... [04:39:15.853] Attaching 1 packages ('future') ... done [04:39:17.838] Launched future #1 > str(list(y = y)) List of 1 $ y:List of 1 ..$ a: chr "hello; 1; 2; ...; 100" > stopifnot(identical(y, y0)) > > > message("- flapply(x, FUN = listenv::listenv, ...) ...") - flapply(x, FUN = listenv::listenv, ...) ... > > x <- list() > > y <- listenv() > y$A <- 3L > x$a <- y > > y <- listenv() > y$A <- 3L > y$B <- c("hello", b = 1:100) > x$b <- y > > print(x) $a A 'listenv' vector with 1 element ('A'). $b A 'listenv' vector with 2 elements ('A', 'B'). > > y0 <- lapply(x, FUN = listenv::mapping) > str(list(y0 = y0)) List of 1 $ y0:List of 2 ..$ a: Named chr "A" .. ..- attr(*, "names")= chr "A" ..$ b: Named chr [1:2] "A" "B" .. ..- attr(*, "names")= chr [1:2] "A" "B" > > y <- flapply(x, FUN = listenv::mapping) [04:39:18.005] Attaching 1 packages ('listenv') ... [04:39:18.013] Attaching 1 packages ('listenv') ... done [04:39:19.210] Launched future #1 [04:39:19.337] Attaching 1 packages ('listenv') ... [04:39:19.352] Attaching 1 packages ('listenv') ... done [04:39:20.682] Launched future #1 > str(list(y = y)) List of 1 $ y:List of 2 ..$ a: Named chr "A" .. ..- attr(*, "names")= chr "A" ..$ b: Named chr [1:2] "A" "B" .. ..- attr(*, "names")= chr [1:2] "A" "B" > stopifnot(identical(y, y0)) > > > message("*** Tricky use cases related to globals ... DONE") *** Tricky use cases related to globals ... DONE > > source("incl/end.R") > > proc.time() user system elapsed 2.95 0.50 15.87