tests/testthat/setup_cluster.R

method <- Sys.getenv("FOREACH_BACKEND", "SEQ")

if(method == "PAR") {
  cl <- parallel::makeCluster(2, type="PSOCK")
  .Last <- function() {
    parallel::stopCluster(cl)
  }
  doParallel::registerDoParallel(cl)
} else if(method == 'MC') {
  doMC::registerDoMC()
} else if(method == 'SEQ') {
  registerDoSEQ()
} else {
  stop('illegal backend specified: ', method)
}

Try the foreach package in your browser

Any scripts or data that you put into this service are public.

foreach documentation built on Feb. 2, 2022, 5:09 p.m.