Running ‘fold.R’ [6s/7s]
  Running ‘future_apply.R’ [4s/21s]
  Running ‘future_by.R’ [5s/21s]
  Running ‘future_eapply.R’ [2s/19s]
  Running ‘future_lapply,RNG.R’ [37s/180s]
  Running ‘future_lapply,globals.R’ [2s/13s]
  Running ‘future_lapply.R’ [15s/34s]
  Running ‘future_mapply,globals.R’ [3s/20s]
  Running ‘future_mapply.R’ [6s/24s]
  Running ‘future_replicate.R’ [4s/20s]
  Running ‘future_sapply.R’ [27s/49s]
  Running ‘future_tapply.R’ [1s/1s]
  Running ‘future_vapply.R’ [9s/32s]
  Running ‘globals,tricky_recursive.R’ [2s/17s]
  Running ‘rng.R’ [1s/1s]
  Running ‘stdout.R’ [3s/34s]
  Running ‘utils.R’ [1s/1s]
Running the tests in ‘tests/future_lapply,globals.R’ failed.
Complete output:
  > source("incl/start.R")
  Loading required package: future
  [14:09:07.491] plan(): Setting new future strategy stack:
  [14:09:07.491] List of future strategies:
  [14:09:07.491] 1. sequential:
  [14:09:07.491]    - args: function (expr, envir = parent.frame(), substitute = TRUE, lazy = FALSE, seed = NULL, globals = TRUE, local = TRUE, earlySignal = FALSE, label = NULL, ...)
  [14:09:07.491]    - tweaked: FALSE
  [14:09:07.491]    - call: future::plan("sequential")
  [14:09:07.493] plan(): nbrOfWorkers() = 1
  > library("tools") ## toTitleCase()
  > 
  > message("*** future_lapply() - globals ...")
  *** future_lapply() - globals ...
  > 
  > plan(cluster, workers = "localhost")
  [14:09:07.558] plan(): Setting new future strategy stack:
  [14:09:07.558] List of future strategies:
  [14:09:07.558] 1. cluster:
  [14:09:07.558]    - args: function (expr, envir = parent.frame(), substitute = TRUE, lazy = FALSE, seed = NULL, globals = TRUE, persistent = FALSE, workers = "localhost", user = NULL, revtunnel = TRUE, homogeneous = TRUE, gc = FALSE, earlySignal = FALSE, label = NULL, ...)
  [14:09:07.558]    - tweaked: TRUE
  [14:09:07.558]    - call: plan(cluster, workers = "localhost")
  [14:09:07.658] plan(): plan_init() of 'tweaked', 'cluster', 'multiprocess', 'future', 'function' ...
  [14:09:07.659] cluster:
  [14:09:07.659] - args: function (expr, envir = parent.frame(), substitute = TRUE, lazy = FALSE, seed = NULL, globals = TRUE, persistent = FALSE, workers = "localhost", user = NULL, revtunnel = TRUE, homogeneous = TRUE, gc = FALSE, earlySignal = FALSE, label = NULL, ...)
  [14:09:07.659] - tweaked: TRUE
  [14:09:07.659] - call: plan(cluster, workers = "localhost")
  [local output] Workers: [n = 1] 'localhost'
  [local output] Base port: 20788
  [local output] Creating node 1 of 1 ...
  [local output] - setting up node
  Testing if worker's PID can be inferred: ''/home/hornik/tmp/R.check/r-patched-gcc/Work/build/bin/Rscript' -e 'try(suppressWarnings(cat(Sys.getpid(),file="/tmp/RtmpgDD0Qd/future.parent=11967.2ebf2eeb15cd.pid")), silent = TRUE)' -e "file.exists('/tmp/RtmpgDD0Qd/future.parent=11967.2ebf2eeb15cd.pid')"'
  - Possible to infer worker's PID: TRUE
  [local output] Starting worker #1 on 'localhost': '/home/hornik/tmp/R.check/r-patched-gcc/Work/build/bin/Rscript' --default-packages=datasets,utils,grDevices,graphics,stats,methods -e '#label=future_lapply,globals.R:11967:gimli:hornik' -e 'try(suppressWarnings(cat(Sys.getpid(),file="/tmp/RtmpgDD0Qd/future.parent=11967.2ebf2eeb15cd.pid")), silent = TRUE)' -e 'parallel:::.slaveRSOCK()' MASTER=localhost PORT=20788 OUT=/dev/null TIMEOUT=120 XDR=TRUE
  [local output] - Exit code of system() call: 0
  [local output] Waiting for worker #1 on 'localhost' to connect back
  [local output] Connection with worker #1 on 'localhost' established
  [local output] - collecting session information
  [local output] Creating node 1 of 1 ... done
  [14:09:15.363] getGlobalsAndPackages() ...
  [14:09:15.363] Not searching for globals
  [14:09:15.364] - globals: [0] <none>
  [14:09:15.365] getGlobalsAndPackages() ... DONE
  [14:09:15.369] Packages needed by the future expression (n = 0): <none>
  [14:09:15.369] Packages needed by future strategies (n = 0): <none>
  [14:09:15.391] {
  [14:09:15.391]     {
  [14:09:15.391]         ...future.startTime <- Sys.time()
  [14:09:15.391]         ...future.oldOptions <- options(future.startup.script = FALSE, 
  [14:09:15.391]             future.globals.onMissing = "ignore", future.globals.maxSize = NULL, 
  [14:09:15.391]             future.globals.method = NULL, future.globals.onMissing = NULL, 
  [14:09:15.391]             future.globals.onReference = NULL, future.globals.resolve = NULL, 
  [14:09:15.391]             future.resolve.recursive = NULL, width = 80L)
  [14:09:15.391]         {
  [14:09:15.391]             {
  [14:09:15.391]                 has_future <- requireNamespace("future", quietly = TRUE)
  [14:09:15.391]                 version <- if (has_future) 
  [14:09:15.391]                   packageVersion("future")
  [14:09:15.391]                 else NULL
  [14:09:15.391]                 if (!has_future || version < "1.8.0") {
  [14:09:15.391]                   info <- c(r_version = gsub("R version ", "", 
  [14:09:15.391]                     R.version$version.string), platform = sprintf("%s (%s-bit)", 
  [14:09:15.391]                     R.version$platform, 8 * .Machine$sizeof.pointer), 
  [14:09:15.391]                     os = paste(Sys.info()[c("sysname", "release", 
  [14:09:15.391]                       "version")], collapse = " "), hostname = Sys.info()[["nodename"]])
  [14:09:15.391]                   info <- sprintf("%s: %s", names(info), info)
  [14:09:15.391]                   info <- paste(info, collapse = "; ")
  [14:09:15.391]                   if (!has_future) {
  [14:09:15.391]                     msg <- sprintf("Package 'future' is not installed on worker (%s)", 
  [14:09:15.391]                       info)
  [14:09:15.391]                   }
  [14:09:15.391]                   else {
  [14:09:15.391]                     msg <- sprintf("Package 'future' on worker (%s) must be of version >= 1.8.0: %s", 
  [14:09:15.391]                       info, version)
  [14:09:15.391]                   }
  [14:09:15.391]                   stop(msg)
  [14:09:15.391]                 }
  [14:09:15.391]             }
  [14:09:15.391]             future::plan("default", .cleanup = FALSE, .init = FALSE)
  [14:09:15.391]         }
  [14:09:15.391]     }
  [14:09:15.391]     if (is.na(TRUE)) {
  [14:09:15.391]     }
  [14:09:15.391]     else {
  [14:09:15.391]         if (TRUE) {
  [14:09:15.391]             ...future.stdout <- rawConnection(raw(0L), open = "w")
  [14:09:15.391]         }
  [14:09:15.391]         else {
  [14:09:15.391]             ...future.stdout <- file(switch(.Platform$OS.type, 
  [14:09:15.391]                 windows = "NUL", "/dev/null"), open = "w")
  [14:09:15.391]         }
  [14:09:15.391]         sink(...future.stdout, type = "output", split = FALSE)
  [14:09:15.391]         on.exit(if (!is.null(...future.stdout)) {
  [14:09:15.391]             sink(type = "output", split = FALSE)
  [14:09:15.391]             close(...future.stdout)
  [14:09:15.391]         }, add = TRUE)
  [14:09:15.391]     }
  [14:09:15.391]     ...future.frame <- sys.nframe()
  [14:09:15.391]     ...future.conditions <- list()
  [14:09:15.391]     ...future.result <- tryCatch({
  [14:09:15.391]         withCallingHandlers({
  [14:09:15.391]             ...future.value <- withVisible(local(NA))
  [14:09:15.391]             future::FutureResult(value = ...future.value$value, 
  [14:09:15.391]                 visible = ...future.value$visible, started = ...future.startTime, 
  [14:09:15.391]                 version = "1.8")
  [14:09:15.391]         }, condition = local({
  [14:09:15.391]             inherits <- base::inherits
  [14:09:15.391]             invokeRestart <- base::invokeRestart
  [14:09:15.391]             length <- base::length
  [14:09:15.391]             seq.int <- base::seq.int
  [14:09:15.391]             sys.calls <- base::sys.calls
  [14:09:15.391]             `[[` <- base::`[[`
  [14:09:15.391]             `+` <- base::`+`
  [14:09:15.391]             `<<-` <- base::`<<-`
  [14:09:15.391]             sysCalls <- function(calls = sys.calls(), from = 1L) {
  [14:09:15.391]                 calls[seq.int(from = from + 12L, to = length(calls) - 
  [14:09:15.391]                   3L)]
  [14:09:15.391]             }
  [14:09:15.391]             function(cond) {
  [14:09:15.391]                 if (inherits(cond, "error")) {
  [14:09:15.391]                   ...future.conditions[[length(...future.conditions) + 
  [14:09:15.391]                     1L]] <<- list(condition = cond, calls = c(sysCalls(from = ...future.frame), 
  [14:09:15.391]                     cond$call), timestamp = base::Sys.time(), 
  [14:09:15.391]                     signaled = 0L)
  [14:09:15.391]                   signalCondition(cond)
  [14:09:15.391]                 }
  [14:09:15.391]                 else if (inherits(cond, "condition")) {
  [14:09:15.391]                   signal <- FALSE && inherits(cond, character(0))
  [14:09:15.391]                   ...future.conditions[[length(...future.conditions) + 
  [14:09:15.391]                     1L]] <<- list(condition = cond, signaled = as.integer(signal))
  [14:09:15.391]                   if (!signal) {
  [14:09:15.391]                     muffleCondition <- function (cond) 
  [14:09:15.391]                     {
  [14:09:15.391]                       inherits <- base::inherits
  [14:09:15.391]                       invokeRestart <- base::invokeRestart
  [14:09:15.391]                       muffled <- FALSE
  [14:09:15.391]                       if (inherits(cond, "message")) {
  [14:09:15.391]                         invokeRestart("muffleMessage")
  [14:09:15.391]                         muffled <- TRUE
  [14:09:15.391]                       }
  [14:09:15.391]                       else if (inherits(cond, "warning")) {
  [14:09:15.391]                         invokeRestart("muffleWarning")
  [14:09:15.391]                         muffled <- TRUE
  [14:09:15.391]                       }
  [14:09:15.391]                       else if (inherits(cond, "condition")) {
  [14:09:15.391]                         computeRestarts <- base::computeRestarts
  [14:09:15.391]                         grepl <- base::grepl
  [14:09:15.391]                         is.null <- base::is.null
  [14:09:15.391]                         restarts <- computeRestarts(cond)
  [14:09:15.391]                         for (restart in restarts) {
  [14:09:15.391]                           name <- restart$name
  [14:09:15.391]                           if (is.null(name)) 
  [14:09:15.391]                             next
  [14:09:15.391]                           if (!grepl("^muffle", name)) 
  [14:09:15.391]                             next
  [14:09:15.391]                           invokeRestart(restart)
  [14:09:15.391]                           muffled <- TRUE
  [14:09:15.391]                           break
  [14:09:15.391]                         }
  [14:09:15.391]                       }
  [14:09:15.391]                       invisible(muffled)
  [14:09:15.391]                     }
  [14:09:15.391]                     muffleCondition(cond)
  [14:09:15.391]                   }
  [14:09:15.391]                 }
  [14:09:15.391]             }
  [14:09:15.391]         }))
  [14:09:15.391]     }, error = function(ex) {
  [14:09:15.391]         structure(list(value = NULL, visible = NULL, conditions = ...future.conditions, 
  [14:09:15.391]             version = "1.8"), class = "FutureResult")
  [14:09:15.391]     }, finally = {
  [14:09:15.391]         {
  [14:09:15.391]             NULL
  [14:09:15.391]             future::plan(list(function (expr, envir = parent.frame(), 
  [14:09:15.391]                 substitute = TRUE, lazy = FALSE, seed = NULL, 
  [14:09:15.391]                 globals = TRUE, persistent = FALSE, workers = "localhost", 
  [14:09:15.391]                 user = NULL, revtunnel = TRUE, homogeneous = TRUE, 
  [14:09:15.391]                 gc = FALSE, earlySignal = FALSE, label = NULL, 
  [14:09:15.391]                 ...) 
  [14:09:15.391]             {
  [14:09:15.391]                 if (substitute) 
  [14:09:15.391]                   expr <- substitute(expr)
  [14:09:15.391]                 future <- ClusterFuture(expr = expr, envir = envir, 
  [14:09:15.391]                   substitute = FALSE, lazy = lazy, seed = seed, 
  [14:09:15.391]                   globals = globals, persistent = persistent, 
  [14:09:15.391]                   workers = workers, user = user, revtunnel = revtunnel, 
  [14:09:15.391]                   homogeneous = homogeneous, gc = gc, earlySignal = earlySignal, 
  [14:09:15.391]                   label = label, ...)
  [14:09:15.391]                 if (!future$lazy) 
  [14:09:15.391]                   future <- run(future)
  [14:09:15.391]                 invisible(future)
  [14:09:15.391]             }), .cleanup = FALSE, .init = FALSE)
  [14:09:15.391]         }
  [14:09:15.391]         options(...future.oldOptions)
  [14:09:15.391]     })
  [14:09:15.391]     if (is.na(TRUE)) {
  [14:09:15.391]     }
  [14:09:15.391]     else {
  [14:09:15.391]         sink(type = "output", split = FALSE)
  [14:09:15.391]         if (TRUE) {
  [14:09:15.391]             ...future.result$stdout <- rawToChar(rawConnectionValue(...future.stdout))
  [14:09:15.391]         }
  [14:09:15.391]         else {
  [14:09:15.391]             ...future.result["stdout"] <- list(NULL)
  [14:09:15.391]         }
  [14:09:15.391]         close(...future.stdout)
  [14:09:15.391]         ...future.stdout <- NULL
  [14:09:15.391]     }
  [14:09:15.391]     ...future.result$conditions <- ...future.conditions
  [14:09:15.391]     ...future.result
  [14:09:15.391] }
  [14:09:15.398] ClusterFuture started
  [14:09:15.400] result() for ClusterFuture ...
  [14:09:15.401] - Validating connection of ClusterFuture
  [14:09:15.582] - class(result): FutureResult
  [14:09:15.590] result() for ClusterFuture ...
  [14:09:15.590] - result already collected: FutureResult
  [14:09:15.591] result() for ClusterFuture ... done
  [14:09:15.591] result() for ClusterFuture ... done
  [14:09:15.591] result() for ClusterFuture ...
  [14:09:15.592] - result already collected: FutureResult
  [14:09:15.592] result() for ClusterFuture ... done
  [14:09:15.593] plan(): plan_init() of 'tweaked', 'cluster', 'multiprocess', 'future', 'function' ... DONE
  [14:09:15.593] plan(): nbrOfWorkers() = 1
  > 
  > options(future.debug = FALSE)
  > a <- 1
  > b <- 2
  > 
  > globals_set <- list(
  +   A = FALSE,
  +   B = TRUE,
  +   C = c("a", "b"),
  +   D = list(a = 2, b = 3)
  + )
  > 
  > x <- list(1)
  > y_truth <- list(A = NULL, B = list(1), C = list(1), D = list(2))
  > str(y_truth)
  List of 4
   $ A: NULL
   $ B:List of 1
    ..$ : num 1
   $ C:List of 1
    ..$ : num 1
   $ D:List of 1
    ..$ : num 2
  > 
  > for (name in names(globals_set)) {
  +   globals <- globals_set[[name]]
  +   message("Globals set ", sQuote(name))
  +   y <- tryCatch({
  +     future_lapply(x, FUN = function(x) {
  +       median(c(x, a, b))
  +     }, future.globals = globals, future.packages = "utils")
  +   }, error = identity)
  +   print(y)
  +   stopifnot((name == "A" && inherits(y, "error")) || 
  +              identical(y, y_truth[[name]]))
  + }
  Globals set 'A'
  <simpleError in median(c(x, a, b)): object 'a' not found>
  Globals set 'B'
  [[1]]
  [1] 1
  
  Globals set 'C'
  [[1]]
  [1] 1
  
  Globals set 'D'
  [[1]]
  [1] 2
  
  > 
  > message("*** future_lapply() - globals ... DONE")
  *** future_lapply() - globals ... DONE
  > 
  > 
  > message("*** future_lapply() - manual globals ...")
  *** future_lapply() - manual globals ...
  > 
  > d <- 42
  > y <- future_lapply(1:2, FUN = function(x) { x * d },
  +                    future.globals = structure(FALSE, add = "d"))
  > stopifnot(identical(y, list(42, 84)))
  > 
  > e <- 42
  > res <- tryCatch({
  +   future_lapply(1:2, FUN = function(x) { 2 * e },
  +                 future.globals = structure(TRUE, ignore = "e"))
  + }, error = identity)
  > stopifnot(inherits(res, "error"))
  > 
  > message("*** future_lapply() - manual globals ... DONE")
  *** future_lapply() - manual globals ... DONE
  > 
  > 
  > 
  > ## Test adopted from http://stackoverflow.com/questions/42561088/nested-do-call-within-a-foreach-dopar-environment-cant-find-function-passed-w
  > 
  > message("*** future_lapply() - tricky globals ...")
  *** future_lapply() - tricky globals ...
  > 
  > my_add <- function(a, b) a + b
  > 
  > call_my_add <- function(a, b) {
  +   do.call(my_add, args = list(a = a, b = b))
  + }
  > 
  > call_my_add_caller <- function(a, b, FUN = call_my_add) {
  +   do.call(FUN, args = list(a = a, b = b))
  + }
  > 
  > main <- function(x = 1:2, caller = call_my_add_caller,
  +                  args = list(FUN = call_my_add)) {
  +   results <- future_lapply(x, FUN = function(i) {
  +     do.call(caller, args = c(list(a = i, b = i + 1L), args))
  +   })
  +   results
  + }
  > 
  > x <- list(list(1:2))
  > z_length <- lapply(x, FUN = do.call, what = length)
  > fun <- function(...) sum(...)
  > z_fun <- lapply(x, FUN = do.call, what = fun)
  > 
  > y0 <- NULL
  > for (strategy in supportedStrategies()) {
  +   plan(strategy)
  + 
  +   y <- main(1:3)
  +   if (is.null(y0)) y0 <- y
  +   stopifnot(identical(y, y0))
  + 
  +   message("- future_lapply(x, FUN = do.call, ...) ...")
  +   z <- future_lapply(x, FUN = do.call, what = length)
  +   stopifnot(identical(z, z_length))
  +   z <- future_lapply(x, FUN = do.call, what = fun)
  +   stopifnot(identical(z, z_fun))
  + 
  +   message("- future_lapply(x, ...) - passing arguments via '...' ...")
  +   ## typeof() == "list"
  +   obj <- data.frame(a = 1:2)
  +   stopifnot(typeof(obj) == "list")
  +   y <- future_lapply(1L, function(a, b) typeof(b), b = obj)
  +   stopifnot(identical(y[[1]], typeof(obj)))
  + 
  +   ## typeof() == "environment"
  +   obj <- new.env()
  +   stopifnot(typeof(obj) == "environment")
  +   y <- future_lapply(1L, function(a, b) typeof(b), b = obj)
  +   stopifnot(identical(y[[1]], typeof(obj)))
  + 
  +   ## typeof() == "S4"
  +   if (requireNamespace("methods")) {
  +     obj <- methods::getClass("MethodDefinition")
  +     stopifnot(typeof(obj) == "S4")
  +     y <- future_lapply(1L, function(a, b) typeof(b), b = obj)
  +     stopifnot(identical(y[[1]], typeof(obj)))
  +   }
  + 
  +   message("- future_lapply(X, ...) - 'X' containing globals ...")
  +   ## From https://github.com/HenrikBengtsson/future.apply/issues/12
  +   a <- 42
  +   b <- 21
  +   X <- list(
  +     function(b) 2 * a,
  +     function() b / 2,
  +     function() a + b,
  +     function() nchar(toTitleCase("hello world"))
  +   )
  +   z0 <- lapply(X, FUN = function(f) f())
  +   str(z0)
  +   z1 <- future_lapply(X, FUN = function(f) f())
  +   str(z1)
  +   stopifnot(identical(z1, z0))
  + }
  - future_lapply(x, FUN = do.call, ...) ...
  - future_lapply(x, ...) - passing arguments via '...' ...
  - future_lapply(X, ...) - 'X' containing globals ...
  List of 4
   $ : num 84
   $ : num 10.5
   $ : num 63
   $ : int 11
  List of 4
   $ : num 84
   $ : num 10.5
   $ : num 63
   $ : int 11
  - future_lapply(x, FUN = do.call, ...) ...
  - future_lapply(x, ...) - passing arguments via '...' ...
  - future_lapply(X, ...) - 'X' containing globals ...
  List of 4
   $ : num 84
   $ : num 10.5
   $ : num 63
   $ : int 11
  List of 4
   $ : num 84
   $ : num 10.5
   $ : num 63
   $ : int 11
  Warning in socketConnection("localhost", port = port, server = TRUE, blocking = TRUE,  :
    port 35918 cannot be opened
  Error in socketConnection("localhost", port = port, server = TRUE, blocking = TRUE,  : 
    Failed to launch and connect to R worker on local machine 'localhost' from local machine 'gimli'.
   * The error produced by socketConnection() was: 'cannot open the connection'
   * In addition, socketConnection() produced 1 warning(s):
     - Warning #1: 'port 35918 cannot be opened' (which suggests that this port is either already occupied by another process or blocked by the firewall on your local machine)
   * The localhost socket connection that failed to connect to the R worker used port 35918 using a communication timeout of 120 seconds and a connection timeout of 120 seconds.
   * Worker launch call: '/home/hornik/tmp/R.check/r-patched-gcc/Work/build/bin/Rscript' --default-packages=datasets,utils,grDevices,graphics,stats,methods -e '#label=future_lapply,globals.R:11967:gimli:hornik' -e 'try(suppressWarnings(cat(Sys.getpid(),file="/tmp/RtmpgDD0Qd/future.parent=11967.2ebf68fbe8a2.pid")), silent = TRUE)' -e 'parallel:::.slaveRSOCK()' MASTER=localhost PORT=35918 OUT=/dev/null TIMEOUT=120 XDR=TRUE.
   * Worker (PID 16499) was successfully killed: TRUE
   * Troubleshooting suggestions:
     - Suggestion #1: Set 'verbose=TRUE' to see more details.
     - Suggestion #2: Set 'outfile=NULL' to see output from worker.
  Calls: plan ... tryCatchList -> tryCatchOne -> <Anonymous> -> <Anonymous>
  Execution halted