-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.qmd
More file actions
117 lines (87 loc) · 4.33 KB
/
index.qmd
File metadata and controls
117 lines (87 loc) · 4.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
---
title: Futureverse
description: A Unifying Parallelization Framework in R for Everyone
preview: images/site_preview.png
bibliography: futureverse.bib
format: html
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE)
```
<div>
<img src="images/logo.png" alt="The hexlogo of the future package. A left-facing arrow with the text future underneath - both in bold style filled with yellow-to-orange vertical gradient. The background is dark blue with teeny star-shaped symbols in distance resembling looking deep out in the universe. The hexlogo is surrounded by a light-blue border." style="width: 15ex; padding-left: 2ex; padding-top: 1ex; padding-bottom: 1ex; float: right;"/>
The **future** framework makes it easy to parallelize existing R code - often with only a minor change of code. The goal is to lower the barriers so that anyone can safely speed up their existing R code in a worry-free manner. As it is a cross-platform solution that requires no additional setups or technical skills, anyone can be up and running within a few minutes.
The future framework _removes common hurdles and protects against pitfalls_ that follow from adding parallelization. Instead of leaving it to the developers and end-users to be aware of and deal with these problems, they are handled at the core of the highly-validated future ecosystem.
Just as with sequential R code, _output, messages, warnings, and errors work as expected_ and can be handled using traditional R techniques - regardless of how the code is parallelized.
It is designed so that you as a developer can _stay with your favorite coding style_, whether it be base R or tidyverse. If you prefer `lapply()`, `map()` of **purrr**, or `foreach()` of **foreach**, there is _no_ need to switch away from that.
Futures make your web interface asynchronous, e.g. a blocking Shiny application can easily be turned into a non-blocking experience by using futures.
Regardless of how you use futures in your code, the user can, with a single setting, switch from running your code sequentially to running it in parallel on their local computer, across multiple machines on their local area network, in the cloud, or distributed on a high-performance compute (HPC) cluster.
For further details and motivations, see @bengtsson-future and @bengtsson-futurize.
</div>
Below is the gist of how to use it ([try it yourself in the live demo](demo.html)):
::: {.panel-tabset}
## **futurize** 💫
```r
library(futurize)
plan(multisession)
## Evaluate an R expression sequentially
y <- slow_fcn(X[1])
## Evaluate it in parallel in the background
f <- future(slow_fcn(X[1]))
y <- value(f)
## Sequential and parallel version of base R apply
y <- lapply(X, slow_fcn)
y <- lapply(X, slow_fcn) |> futurize()
## Sequential and parallel version of purrr map
library(purrr)
y <- X |> map(slow_fcn)
y <- X |> map(slow_fcn) |> futurize()
## Sequential and parallel version of foreach
library(foreach)
y <- foreach(x = X) %do% slow_fcn(x)
y <- foreach(x = X) %do% slow_fcn(x) |> futurize()
```
_The `futurize()` function rewrites the expression to use the corresponding **future.apply**, **furrr**, and **doFuture** expression. It is part of the **[futurize]** package released in January 2026._
## Pre-**futurize**
```r
library(future)
plan(multisession)
## Evaluate an R expression sequentially
y <- slow_fcn(X[1])
## Evaluate it in parallel in the background
f <- future(slow_fcn(X[1]))
y <- value(f)
## Futurized version of base R apply via future.apply
library(future.apply)
y <- lapply(X, slow_fcn)
y <- future_lapply(X, slow_fcn)
## Futurized version of purrr via furrr
library(purrr)
library(furrr)
y <- X |> map(slow_fcn)
y <- X |> future_map(slow_fcn)
## Futurized version of foreach via doFuture (modern)
library(foreach)
library(doFuture)
y <- foreach(x = X) %do% slow_fcn(x)
y <- foreach(x = X) %dofuture% slow_fcn(x)
## Futurized version of foreach via doFuture (traditional)
library(foreach)
doFuture::registerDoFuture()
y <- foreach(x = X) %do% slow_fcn(x)
y <- foreach(x = X) %dopar% slow_fcn(x)
```
:::
<!--
<style>
d-title {
background-image: url(images/logo.png);
background-repeat: no-repeat;
background-origin: content-box;
background-position: calc(100% - 4ex);
background-size: 15ex;
min-height: 15ex;
}
</style>
-->
[futurize]: https://futurize.futureverse.org