Parallelize Your R Code with a Single Tweak
- Easier than Ever Before



Henrik Bengtsson

University of California, San Francisco

R Foundation, R Consortium, Bioconductor

@HenrikBengtsson



COMPUTE! 2026

Paris, France, November 25, 2026

TL;DR: From sequential to parallel processing in 10 years…


Sequential:

res <- lapply(patients, fit_model)
→

Parallel with live progress:

res <- lapply(patients, fit_model) |>
         futurize() |>
         progressify()



That’s it — thank you for your attention! 👋

Data keep growing, but R is single-process at its core

  • Datasets keep growing - larger cohorts, more replicates, more simulations
  • R itself evaluates your code in a single process - one CPU core at a time





← 32× CPU cores sitting idle

Parallelization can help →

Barrier is friction!

Parallelizing used to require abandoning existing code

Before: sequential, readable, auditable

res <- lapply(patients, fit_model)

💡 Futureverse design goal
- I want your focus to stay here!

After: parallel, hard to read, hard to maintain

library(parallel)

if (parallel) {
  if (.Platform$OS.type == "windows") {
    cl <- makeCluster(8)
    res <- parLapply(cl, patients, fit_model)
    stopCluster(cl)
  } else {
    options(mc.cores = 8)
    res <- mclapply(patients, fit_model)
  }
} else {
  res <- lapply(patients, fit_model)
}

Code coverage (Linux CI)
 hit   never run 
only mclapply() and lapply() are hit

⚠️ “Too distractive and error prone”
Refactoring tax
  • Many parallelization APIs
  • Complicated to test
  • Expensive to maintain

Futureverse was introduced to lower refactoring tax

Before: sequential, readable, auditable

After: parallel, readable, maintainable


res <- lapply(patients, fit_model)
library(future.apply)
plan(multisession)
res <- future_lapply(patients, fit_model)
library(purrr)

res <- map(patients, fit_model)
library(furrr)
plan(multisession)
res <- future_map(patients, fit_model)
library(foreach)

res <- foreach(p = patients) %do% {
  fit_model(p) 
}
library(doFuture)
plan(multisession)
res <- foreach(p = patients) %dofuture% {
  fit_model(p) 
}

Key idea: separate what from how and where

Developer declares what may run in parallel

res <- future_lapply(xs, fit_model)


End user decides how and where it runs

plan(multisession)              # laptop
plan(cluster, workers = hosts)  # remote
plan(batchtools_slurm)          # HPC

The R community has embraced the Futureverse



+40% reverse dependencies yearly
(~575 direct, ~1,300 recursive)


Top 0.6% most downloaded packages

… but, we can simplify it further with ‘futurize’




All you need to remember is futurize()

New package futurize preserves your original code

  • Universal adapter: One unifying function futurize()
  • Zero rewrites: Original logic unchanged
res <- lapply(patients, fit_model)
res <- lapply(patients, fit_model) |>
         futurize()
library(purrr)
res <- map(patients, fit_model) |>
         futurize()
library(foreach)
res <- foreach(p = patients) %do% {
  fit_model(p)
} |> futurize()
library(plyr)
res <- llply(patients, fit_model) |>
         futurize()
library(BiocParallel)
res <- bplapply(patients, fit_model) |>
         futurize()

Easy!

Same code scales from laptop to cloud to HPC

plan() Environment Use case
sequential Single machine Sequential (default, debugging)
multisession Single machine Parallel across multiple cores
mirai_multisession Single machine Same as above; powered by mirai
mizu_multisession Single machine Same as above; shared memory via mizu (new)
cluster Many machines Parallel across many machines (desktops, cloud)
batchtools_* Slurm/SGE/LSF Scheduler-based HPC clusters
library(futurize)
plan(future.batchtools::batchtools_slurm)
res <- purrr::map(patients, fit_model) |> futurize()

Under the hood: transpilation at work

Source-to-source code translation

  • futurize() inspects the expression on the left
  • Dynamically rewrites the call to its parallel equivalent
  • Executes it within Futureverse

Eliminates the refactoring tax

  • No manual rewrites: Keep your code clean and readable
  • No package lock-in: Seamlessly adapts to your preferred package API (base, purrr, foreach, etc.)

Automatic code rewriting

# What you write:
res <- lapply(xs, fit_model) |> futurize()
# What is executed under the hood:
-lapply(xs, fit_model)
+future.apply::future_lapply(xs, fit_model)


# What you write:
res <- map(xs, fit_model) |> futurize()
# What is executed under the hood:
-map(xs, fit_model)
+furrr::future_map(xs, fit_model)

Why can R do this? Lazy evaluation

The pipe is just syntax

res <- lapply(xs, fit_model) |> futurize()

is parsed as

res <- futurize(lapply(xs, fit_model))

Arguments are evaluated lazily

futurize <- function(expr) {
  ## get the code, not its value
  expr <- substitute(expr)
  
  ## lapply() -> future_lapply()
  
  ## ... then evaluate
}

futurize() receives the code
before it runs

Minimal AST manipulation: evil_eval()

Toy example: swap + with -

evil_eval <- function(expr) {
  ## Capture unevaluated AST: `+`(1, 2)
  expr <- substitute(expr)
  
  ## Swap root symbol: `+` -> `-`
  expr[[1]] <- as.symbol("-")
  
  ## Evaluate rewritten AST: `-`(1, 2)
  eval(expr, parent.frame())
}

evil_eval(1 + 2)
#> [1] -1

lapply(xs, f) |> futurize() does the exact same thing:

  1. Captures the call: substitute() captures lapply(xs, f) without evaluating it

  2. Inspects root symbol: expr[[1]] is lapply

  3. Rewrites the AST: swaps lapply to future_lapply

  4. Evaluates: runs the parallel version in caller’s environment

… we can do even more with ‘futurize’




All you need to remember is futurize()

futurize() works with a growing set of domain-specific packages

CRAN Package Use
boot Bootstrap resampling
caret Machine learning training
DiceKriging Kriging models
ez Easy analysis of variance
fwb Fractional weighted bootstrap
gamlss Generalized additive models
glmmTMB Generalized linear mixed models
glmnet Lasso & elastic-net
kernelshap Kernel SHAP explanations
lme4 Linear mixed-effects models
metafor Meta-analysis models
mgcv Generalized additive models
mlr3 Machine learning framework
mlr3tuning Hyperparameter tuning
modelsummary Model summaries & tables
parameters Model parameters
partykit Recursive partitioning
CRAN Package Use
pls Partial least squares
pvclust Hierarchical clustering
riskRegression Risk regression (survival)
rugarch GARCH time-series models
sandwich Robust covariance estimators
seriation Data ordering
shapr Shapley value explanations
Sim.DiffProc Stochastic differential equations
SimDesign Monte Carlo simulation studies
stars Spatiotemporal data cubes
strucchange Structural change tests
SuperLearner Super Learner ensembles
terra Spatial raster data
tm Text mining
TSP Traveling salesperson problem
vegan Community ecology
Bioc Package Use
BiocParallel Map-reduce infrastructure
bumphunter Differentially methylated regions
DESeq2 Differential gene expression
fgsea Fast gene set enrichment
GenomicAlignments Genomic alignments (BAM)
GSVA Gene set variation analysis
Rsamtools Rsamtools utilities
scater Single-cell transformations
scuttle Single-cell utilities
SingleCellExperiment Single-cell containers
sva Surrogate variable analysis

Bootstrap simulations accelerated with futurize()

Sequential:

library(boot)
b <- boot(data = cohort, statistic = cox_stat, R = 100e3)

100,000 bootstrap replicates takes hours on large cohorts!

A single worker

Parallel:

plan(future.mirai::mirai_multisession)
library(boot)
b <- boot(data = cohort, statistic = cox_stat, R = 100e3) |>
     futurize()

Faster when distributed across parallel workers.
Identical results.

32 parallel workers

It is very well tested: the CRAN trust model


  • Nightly testing across 25,000+ packages:
    Full R CMD check runs nightly across Linux, macOS, Windows, and R versions.
  • Mandatory reverse-dependency checks:
    CRAN policy requires maintainers to test downstream packages before submitting updates.
  • Maintainer effort = end-user trust:
    Maintainers absorb the maintenance workload so end users and tools get rock-solid stability.

Yes, we can do progress reporting too




All you need to remember is progressify()

Progress reporting with ‘progressify’

Vanilla call:

res <- lapply(patients, fit_model)


With progress reporting:

library(progressify)
handlers("cli", globals = TRUE)

res <- lapply(patients, fit_model) |> 
         progressify()

■■■■■■■■■■■■■■■■80% | ETA: 12m

In parallel with progress reporting:

library(progressify)
handlers("cli", globals = TRUE)

library(futurize)
plan(multisession)

res <- lapply(patients, fit_model) |> 
         progressify() |> 
         futurize()

■■■■■■■■■■■■■■■■80% | ETA: 23s

Easy!

Resource specifications: preventing waste & OOMs

  • The problem: Resource blindness in R
## NOTE: fit_model(patient) requires ~8 GiB
res <- lapply(patients, fit_model)

#> Killed (after 1.5 hours)
#> [kernel] Memory cgroup out of memory: Killed process 48213 (R), memory.max=4G
  • Declare what is needed - fail fast with an informative error:

    res <- lapply(patients, fit_model) |> 
             resources(memory = 8*GiB)
    
    #> Error: Cannot meet resources(memory = 8 GiB): this R session
    #> has only 4 GiB of memory available (cgroups v2 memory.max)
  • In parallel: as many workers as fit in memory:
plan(multisession)
res <- lapply(patients, fit_model) |> 
         resources(memory = 8*GiB) |> 
         futurize()
         
#> Using 6 of 32 cores: 
#> 6 workers x 8 GiB = 48 GiB fits within the 50 GiB 
#> memory limit (cgroups v2 memory.max)
  • On HPC: translated into scheduler declarations:
plan(batchtools_slurm)
res <- lapply(patients, fit_model) |> 
         resources(memory = 8*GiB) |> 
         futurize()
         
#> Submitting Slurm jobs with:
#>   #SBATCH --mem=8G
  • Best: declared once, by the maintainer of fit_model():

    ## Package maintainer declares what fit_model() needs
    fit_model <- function(patient) {
      ...
    }
    resources(fit_model) <- resources(memory = 1.5 * size_of(patient))
    
    ## Users need not know - works as before
    res <- lapply(patients, fit_model) |> 
             futurize()

Dreaming big: intent-based computing

  • Declare operational goals, not low-level hardware:

    res <- lapply(patients, fit_model) |> 
             resources(by = "08:00", budget = 25*USD) |> 
             futurize()
  • Deadlines: finish before morning (by = "08:00").

  • Cost ceilings: cap commercial cloud or spot-instance spend (budget = 25*USD).

  • Automated backend routing: dynamically negotiate across local cores, HPC clusters, and cloud resources to meet deadlines within budget.

  • Alternatively, fail fast if the goals cannot be met:

    #> Error: Cannot finish by 08:00 within budget = 25 USD;
    #> the 08:00 deadline requires budget = 100*USD

Thank you - may the future be with you!

Easy to install:

install.packages(c("futurize", "progressify"))

Easy to use:

ys <- lapply(xs, fcn) |> progressify() |> futurize()

Stay with your favorite coding style:

ys <- xs |> map(fcn) |> progressify() |> futurize()

Available elsewhere too:

ys <- glmnet::cv.glmnet(x, y) |> futurize()