The future Framework
Use plan(multisession) and future() for asynchronous, portable parallelism.
What Is the future Package?
The future package provides a unified, high-level API for asynchronous and parallel programming in R. A future is a placeholder for a value that will be available later — possibly computed on another core or machine.
library(future)
# A simple future: computation happens asynchronously
f <- future({
Sys.sleep(0.5) # simulate slow work
42
})
cat('Future created, doing other work...\n')
# Retrieve the result (blocks until done)
result <- value(f)
cat('Result:', result, '\n')plan(): Choosing a Backend
plan() sets the execution strategy for all subsequent futures. The most common strategies are sequential (default, single-threaded), multisession (multiple R sessions, works everywhere), and multicore (forking, Unix/macOS only).
library(future)
# Default: sequential (no parallelism)
plan(sequential)
cat('Strategy:', class(plan())[1], '\n')
# Parallel with separate R sessions (works on Windows too)
plan(multisession, workers = 4)
cat('Strategy:', class(plan())[1], '\n')
# Forking (Unix/macOS only, lower overhead)
if (.Platform$OS.type != 'windows') {
plan(multicore, workers = 4)
cat('Strategy:', class(plan())[1], '\n')
}
# Reset to sequential
plan(sequential)