Learn R Programming

mirai

ミライ

moving already Minimalist Async Evaluation Framework for R

→ Event-driven core with microsecond round-trips

→ Hub architecture — scale dynamically from laptop to HPC and cloud

→ Production-ready distributed tracing, custom serialization, and Shiny integration

Installation

install.packages("mirai")

Quick Start

mirai() evaluates an R expression asynchronously in a parallel process.

daemons() sets up daemons: persistent background processes that receive and execute tasks.

library(mirai)

# Set up 5 background processes
daemons(5)

# Send work -- non-blocking, returns immediately
m <- mirai({
  Sys.sleep(1)
  100 + 42
})
m
#> < mirai [] >

# Map work across daemons in parallel
mp <- mirai_map(1:9, \(x) {
  Sys.sleep(1)
  x^2
})
mp
#> < mirai map [0/9] >

# Collect results when ready
m[]
#> [1] 142
mp[.flat]
#> [1]  1  4  9 16 25 36 49 64 81

# Shut down
daemons(0)

See the quick reference for a full introduction.

Architecture

mirai() sends tasks to daemons for parallel execution.

A compute profile is a set of connected daemons. Multiple profiles can coexist, directing tasks to different resources.

Hub architecture: host listens at a URL, daemons connect to it — add or remove daemons at any time. Launch locally or remotely via different methods, and mix freely:

Design Philosophy

Dynamic Architecturescale on demand

  • Host listens, daemons connect — true dynamic scaling
  • Optimal load balancing via efficient FIFO scheduling
  • Event-driven promises with zero-latency completion

Modern Foundationbuilt for speed

  • NNG via nanonext — thousands of processes at scale
  • Round-trip times in microseconds, not milliseconds
  • IPC, TCP, and zero-config TLS certificates

Production Firstreliable by design

  • Explicit dependencies prevent hidden-state surprises
  • Cross-language serialization (torch, Arrow, Polars)
  • OpenTelemetry for distributed process observability

Deploy Everywherelaptop to cluster

  • Local machine, SSH remote, HPC cluster, or cloud platform
  • Compute profiles direct tasks to best-fit resources
  • Combine resources from any deployment type in a single profile

Async Foundation for the Modern R Stack

mirai has become the convergence point for asynchronous and parallel computing across the R ecosystem.

  The first official alternative communications backend for R, a parallel cluster type.

  Powers parallel map for purrr, the tidyverse’s functional programming toolkit.

  Primary async backend for Shiny, with full ExtendedTask support.

  Built-in async evaluator enabling the @async tag in plumber2.

  Parallel processing backend for ragnar, a RAG framework for R.

  Core parallel processing infrastructure provider for tidymodels.

  Seamless use of torch tensors, models and optimizers across parallel processes.

  Query databases over ADBC connections natively in the Arrow data format.

 Native handling of Polars objects across parallel processes via serialization hooks.

  Powers targets pipelines via crew, a distributed worker launcher built on mirai.

Acknowledgements

Will Landau for being instrumental in shaping development of the package, from initiating the original request for persistent daemons, through to orchestrating robustness testing for the high performance computing requirements of crew and targets.

Joe Cheng for integrating the ‘promises’ method to work seamlessly within Shiny, and prototyping event-driven promises.

Luke Tierney of R Core, for discussion on L’Ecuyer-CMRG streams to ensure statistical independence in parallel processing, and reviewing mirai’s implementation as the first ‘alternative communications backend for R’.

Travers Ching for a novel idea in extending the original custom serialization support in the package.

Hadley Wickham, Henrik Bengtsson, Daniel Falbel, and Kirill Müller for many deep insights and discussions.

Links

mirai | nanonext | CRAN HPC Task View

Please note that this project is released with a Contributor Code of Conduct. By participating in this project you agree to abide by its terms.

Copy Link

Version

Install

install.packages('mirai')

Monthly Downloads

46,439

Version

2.6.0

License

MIT + file LICENSE

Issues

Pull Requests

Stars

Forks

Maintainer

Charlie Gao

Last Published

February 13th, 2026

Functions in mirai (2.6.0)

with.miraiDaemons

With Mirai Daemons
with_daemons

With Daemons
status

Status Information
register_serial

Register Serialization Configuration
remote_config

Generic Remote Launch Configuration
info

Information Statistics
stop_mirai

mirai (Stop)
unresolved

Query if a mirai is Unresolved
mirai_map

mirai Map
ssh_config

SSH Remote Launch Configuration
nextstream

Next >> Developer Interface
.flat

mirai Map Options
collect_mirai

mirai (Collect Value)
as.promise.mirai

Make mirai Promise
dispatcher

Dispatcher
daemons_set

Query if Daemons are Set
daemon

Daemon Instance
call_mirai

mirai (Call Value)
as.promise.mirai_map

Make mirai_map Promise
cluster_config

Cluster Remote Launch Configuration
daemons

Daemons (Set Persistent Processes)
everywhere

Evaluate Everywhere
is_mirai

Is mirai / mirai_map
mirai-package

mirai: Minimalist Async Evaluation Framework for R
make_cluster

Make Mirai Cluster
launch_local

Launch Daemons
http_config

HTTP Remote Launch Configuration
host_url

URL Constructors
is_mirai_error

Error Validators
on_daemon

On Daemon
require_daemons

Require Daemons
mirai

mirai (Evaluate Async)
serial_config

Create Serialization Configuration
race_mirai

mirai (Race)