View source: R/mirai_multisession.R

mirai_multisession | R Documentation |

Mirai-based localhost multisession futures

```
mirai_multisession(
expr,
substitute = TRUE,
envir = parent.frame(),
...,
workers = availableCores()
)
```

`expr` |
An |

`substitute` |
If TRUE, argument |

`envir` |
The environment from where global objects should be identified. |

`...` |
Additional named elements of the future. |

`workers` |
The number of parallel processes to use.
If a function, it is called without arguments |

An object of class MiraiFuture.

```
plan(mirai_multisession)
# A function that returns a future, note that N uses lexical scoping...
f <- function() future({4 * sum((runif(N) ^ 2 + runif(N) ^ 2) < 1) / N}, seed = TRUE)
# Run a simple sampling approximation of pi in parallel using M * N points:
N <- 1e6 # samples per worker
M <- 10 # iterations
pi_est <- Reduce(sum, Map(value, replicate(M, f()))) / M
print(pi_est)
plan(sequential)
invisible(mirai::daemons(0)) ## Shut down mirai workers
```

Embedding an R snippet on your website

Add the following code to your website.

For more information on customizing the embed code, read Embedding Snippets.