1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98
|
source("incl/start.R")
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 ...")
message("- Globals with the same name as 'base' objects ...")
## 'col' is masked by 'base::col' (Issue #55)
col <- 3
x %<-% { stopifnot(is.numeric(col)); col }
print(x)
stopifnot(x == col)
## https://github.com/mllg/batchtools/issues/88
message("- Globals that don't necessarily map to filenames ...")
.a <- 42L
x %<-% { .a }
print(x)
stopifnot(x == .a)
`$foo` <- 42L
x %<-% { `$foo` }
print(x)
stopifnot(x == `$foo`)
message("- 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))
y0 <- lapply(x, FUN = base::vector, length = 2L)
str(list(y0 = y0))
y <- flapply(x, FUN = base::vector, length = 2L)
str(list(y = y))
stopifnot(identical(y, y0))
message("- flapply(x, FUN = future:::hpaste, ...) ...")
x <- list(a = c("hello", b = 1:100))
str(list(x = x))
y0 <- lapply(x, FUN = future:::hpaste, collapse = "; ", maxHead = 3L)
str(list(y0 = y0))
y <- flapply(x, FUN = future:::hpaste, collapse = "; ", maxHead = 3L)
str(list(y = y))
stopifnot(identical(y, y0))
message("- 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)
y0 <- lapply(x, FUN = listenv::mapping)
str(list(y0 = y0))
y <- flapply(x, FUN = listenv::mapping)
str(list(y = y))
stopifnot(identical(y, y0))
message("*** Tricky use cases related to globals ... DONE")
source("incl/end.R")
|