future.batchtools: future.batchtools: A Future for batchtools

future.batchtoolsR Documentation

future.batchtools: A Future for batchtools

Description

The future.batchtools package implements the Future API on top of batchtools such that futures can be resolved on for instance high-performance compute (HPC) clusters via job schedulers. The Future API is defined by the future package.

Details

To use batchtools futures, attach future, and select the type of future you wish to use via future::plan().

Example

library(futurize)                          # also attaches 'future'
plan(future.batchtools::batchtools_slurm)  # parallelize via Slurm jobs

# A slow function
slow_fcn <- function(x) {
  Sys.sleep(1.0)
  x^2
}

# Example data
xs <- 1:10

# Sequential and parallel base R apply
ys <- lapply(xs, slow_fcn)
ys <- lapply(xs, slow_fcn) |> futurize()

# Sequential and parallel purrr map
library(purrr)
ys <- xs |> map(slow_fcn)
ys <- xs |> map(slow_fcn) |> futurize()

# Sequential and parallel foreach calls
library(foreach)
ys <- foreach(x = xs) %do% slow_fcn(x)
ys <- foreach(x = xs) %do% slow_fcn(x) |> futurize()

Author(s)

Maintainer: Henrik Bengtsson henrikb@braju.com (ORCID) [copyright holder]

Authors:

Other contributors:

  • Michel Lang (ORCID) (Code adapted from the 'batchtools' package) [contributor, copyright holder]

  • Bernd Bischl (ORCID) (Code adapted from the 'batchtools' package) [contributor, copyright holder]

See Also

Useful links:


future.batchtools documentation built on Nov. 23, 2026, 1:07 a.m.