Learn R Programming

⚠️There's a newer version (2.4.1) of this package.Take me there.

mirai

ミライ

みらい 未来 Minimalist Async Evaluation Framework for R → Designed for simplicity, a ‘mirai’ evaluates an R expression asynchronously in a parallel process, locally or distributed over the network.

→ Modern networking and concurrency, built on nanonext and NNG (Nanomsg Next Gen), ensures reliable and efficient scheduling over fast inter-process communications or TCP/IP secured by TLS. Distributed computing can launch remote resources via SSH or cluster managers.

→ A queued architecture readily handles more tasks than available processes, requiring no storage on the file system. Innovative features include event-driven promises, asynchronous parallel map, and automatic serialization of otherwise non-exportable reference objects.

Quick Start

Use mirai() to evaluate an expression asynchronously in a separate, clean R process.

The following mimics an expensive calculation that eventually returns a vector of random values.

library(mirai)

m <- mirai({Sys.sleep(n); rnorm(n, mean)}, n = 5L, mean = 7)

The mirai expression is evaluated in another process and hence must be self-contained, not referring to variables that do not already exist there. Above, the variables n and mean are passed as part of the mirai() call.

A ‘mirai’ object is returned immediately - creating a mirai never blocks the session.

m
#> < mirai [] >

Whilst the async operation is ongoing, attempting to access a mirai’s data yields an ‘unresolved’ logical NA.

m$data
#> 'unresolved' logi NA

To check whether a mirai remains unresolved (yet to complete):

unresolved(m)
#> [1] TRUE

To wait for and collect the return value, use the mirai’s [] method:

m[]
#> [1] 6.288799 7.337810 6.767335 7.435713 7.628763

As a mirai represents an async operation, it is never necessary to wait for it. Once it completes, the return value is automatically available at $data.

while (unresolved(m)) {
  # do work here that does not depend on `m`
}
m$data
#> [1] 6.288799 7.337810 6.767335 7.435713 7.628763

Daemons

Copy Link

Version

Install

install.packages('mirai')

Monthly Downloads

6,309

Version

2.3.0

License

MIT + file LICENSE

Issues

Pull Requests

Stars

Forks

Maintainer

Charlie Gao

Last Published

July 15th, 2025

Functions in mirai (2.3.0)

on_daemon

On Daemon
is_mirai

Is mirai / mirai_map
launch_local

Launch Daemon
mirai_map

mirai Map
register_serial

Register Serialization Configuration
everywhere

Evaluate Everywhere
mirai-package

mirai: Minimalist Async Evaluation Framework for R
host_url

URL Constructors
mirai

mirai (Evaluate Async)
make_cluster

Make Mirai Cluster
nextstream

Next >> Developer Interface
is_mirai_error

Error Validators
remote_config

Generic and SSH Remote Launch Configuration
serial_config

Create Serialization Configuration
with.miraiDaemons

With Mirai Daemons
unresolved

Query if a mirai is Unresolved
status

Status Information
stop_mirai

mirai (Stop)
as.promise.mirai

Make mirai Promise
dispatcher

Dispatcher
daemons_set

Daemons Set
collect_mirai

mirai (Collect Value)
call_mirai

mirai (Call Value)
call_mirai_

Call mirai
as.promise.mirai_map

Make mirai_map Promise
daemon

Daemon Instance
daemons

Daemons (Set Persistent Processes)
.flat

mirai Map Options