inst/testme/test-globals,tricky2.R

#' @tags future_apply
#' @tags globals
#' @tags detritus-files
#' @tags sequential multisession multicore

if (packageVersion("future") > "1.49.0" && isTRUE(getOption("future.globals.keepWhere"))) {

  library(future.apply)
  options(future.debug = FALSE)
  
  foo <- function(..., FUN = function(...) list(...)) {
    args <- list(...)
    future_lapply(1L, FUN = function(x) {
      do.call(FUN, args = c(list(x), args))
    })
  }
  
  bar <- function(..., fun = function(...) list(...)) {
    future_lapply(1L, FUN = function(x) fun(x, ...))
  }
  
  yaa <- function(..., FUN = function(...) list(...)) {
    future_lapply(1L, FUN = function(x) {
      do.call(FUN, args = c(list(x), ...))
    })
  }
  
  for (strategy in supportedStrategies()) {
    message(sprintf("- plan('%s') ...", strategy))
    plan(strategy)
  
    x1 <- foo()
    y1 <- bar()
    stopifnot(identical(y1, x1))
    z1 <- yaa()
    stopifnot(identical(z1, x1))
  
    x2 <- foo(a = 2)
    y2 <- bar(a = 2)
    z2 <- yaa(a = 2)
    stopifnot(identical(y2, x2))
    stopifnot(identical(z2, x2))
    
    message(sprintf("- plan('%s') ... done", strategy))
  }

} ## if (packageVersion("future") > ...)
HenrikBengtsson/future.apply documentation built on June 13, 2025, 8 p.m.