furrr

Apply Mapping Functions in Parallel using Futures

https://github.com/futureverse/furrr

Science Score: 23.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
  • DOI references
  • Academic publication links
  • Committers with academic emails
    1 of 6 committers (16.7%) from academic institutions
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (18.3%) to scientific vocabulary

Keywords from Contributors

tidy-data documentation-tool structural-equation-modeling
Last synced: 11 months ago · JSON representation

Repository

Apply Mapping Functions in Parallel using Futures

Basic Info
Statistics
  • Stars: 728
  • Watchers: 21
  • Forks: 38
  • Open Issues: 21
  • Releases: 7
Created over 8 years ago · Last pushed over 1 year ago
Metadata Files
Readme Changelog License Code of conduct

README.Rmd

---
output: github_document
editor_options:
  chunk_output_type: console
---



```{r setup, include = FALSE}
knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  fig.path = "man/figures/README-",
  out.width = "100%"
)
```

```{r, echo=FALSE, message=FALSE, warning=FALSE}
library(furrr)
library(purrr)
library(tictoc)
```

# furrr 


[![CRAN status](https://www.r-pkg.org/badges/version/furrr)](https://cran.r-project.org/package=furrr)
[![R-CMD-check](https://github.com/futureverse/furrr/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/futureverse/furrr/actions/workflows/R-CMD-check.yaml)
[![Codecov test coverage](https://codecov.io/gh/futureverse/furrr/graph/badge.svg)](https://app.codecov.io/gh/futureverse/furrr)


## Overview

The goal of furrr is to combine purrr's family of mapping functions with future's parallel processing capabilities. The result is near drop in replacements for purrr functions such as `map()` and `map2_dbl()`, which can be replaced with their furrr equivalents of `future_map()` and `future_map2_dbl()` to map in parallel.

The code draws heavily from the implementations of purrr and future.apply and this package would not be possible without either of them.

## What has been implemented?

Every variant of the following functions has been implemented:

- `map()`
- `map2()`
- `pmap()`
- `walk()`
- `imap()`
- `modify()`

This includes atomic variants like `map_dbl()` through `future_map_dbl()` and predicate variants like `map_at()` through `future_map_at()`.

## Installation

You can install the released version of furrr from [CRAN](https://CRAN.R-project.org) with:

``` r
install.packages("furrr")
```

And the development version from [GitHub](https://github.com/) with:

``` r
# install.packages("remotes")
remotes::install_github("futureverse/furrr")
```

## Learning

The easiest way to learn about furrr is to browse [the website](https://furrr.futureverse.org/). In particular, the [function reference](https://furrr.futureverse.org/reference/index.html) page can be useful to get a general overview of the functions in the package, and the following vignettes are deep dives into various parts of furrr:

- [Common gotchas](https://furrr.futureverse.org/articles/articles/gotchas.html)

- [Learn how furrr "chunks" your input](https://furrr.futureverse.org/articles/articles/chunking.html)

- [carrier - An alternative to automatic globals detection](https://furrr.futureverse.org/articles/articles/carrier.html)

- [Progress notifications with progressr](https://furrr.futureverse.org/articles/articles/progress.html)

- [Using furrr with connections](https://furrr.futureverse.org/articles/articles/remote-connections.html)

## Example

furrr has been designed to function as identically to purrr as possible, so that you can immediately have familiarity with it.

```{r example}
library(furrr)
library(purrr)

map(c("hello", "world"), ~.x)

future_map(c("hello", "world"), ~.x)
```

The default backend for future (and through it, furrr) is a sequential one. This means that the above code will run out of the box, but it will _not_ be in parallel. The design of future makes it incredibly easy to change this so that your code will run in parallel.

```{r}
# Set a "plan" for how the code should run.
plan(multisession, workers = 2)

# This does run in parallel!
future_map(c("hello", "world"), ~.x)
```

```{r, echo=FALSE}
# Shut down workers
plan(sequential)
```

If you are still skeptical, here is some proof that we are running in parallel.

```{r, eval=FALSE}
library(tictoc)

# This should take 6 seconds in total running sequentially
plan(sequential)

tic()
nothingness <- future_map(c(2, 2, 2), ~Sys.sleep(.x))
toc()
#> 6.08 sec elapsed
```

```{r, eval=FALSE}
# This should take ~2 seconds running in parallel, with a little overhead
# in `future_map()` from sending data to the workers. There is generally also
# a one time cost from `plan(multisession)` setting up the workers.
plan(multisession, workers = 3)

tic()
nothingness <- future_map(c(2, 2, 2), ~Sys.sleep(.x))
toc()
#> 2.212 sec elapsed
```

## Data transfer

It's important to remember that data has to be passed back and forth between the workers. This means that whatever performance gain you might have gotten from your parallelization can be crushed by moving large amounts of data around. For example, if you are moving large data frames to the workers, running models in parallel, and returning large model objects back, the shuffling of data can take a large chunk of that time. Rather than returning the entire model object, you might consider only returning a performance metric, or smaller specific pieces of that model that you are most interested in.

This performance drop can especially be prominent if using `future_pmap()` to iterate over rows and return large objects at each iteration.

Owner

  • Name: Futureverse
  • Login: futureverse
  • Kind: organization

A Unifying Parallelization Framework in R for Everyone

GitHub Events

Total
  • Issues event: 10
  • Watch event: 22
  • Issue comment event: 8
  • Push event: 8
  • Pull request event: 4
  • Create event: 1
Last Year
  • Issues event: 10
  • Watch event: 22
  • Issue comment event: 8
  • Push event: 8
  • Pull request event: 4
  • Create event: 1

Committers

Last synced: about 1 year ago

All Time
  • Total Commits: 292
  • Total Committers: 6
  • Avg Commits per committer: 48.667
  • Development Distribution Score (DDS): 0.247
Past Year
  • Commits: 5
  • Committers: 2
  • Avg Commits per committer: 2.5
  • Development Distribution Score (DDS): 0.4
Top Committers
Name Email Commits
DavisVaughan d****s@r****m 220
DavisVaughan m****5@u****u 66
aaronpeikert a****t@p****e 2
Henrik Bengtsson h****n@g****m 2
Mikkel Meyer Andersen m****k 1
Lionel Henry l****y@g****m 1
Committer Domains (Top 20 + Academic)

Issues and Pull Requests

Last synced: 11 months ago

All Time
  • Total issues: 84
  • Total pull requests: 27
  • Average time to close issues: 2 months
  • Average time to close pull requests: 9 days
  • Total issue authors: 62
  • Total pull request authors: 4
  • Average comments per issue: 3.05
  • Average comments per pull request: 0.22
  • Merged pull requests: 22
  • Bot issues: 0
  • Bot pull requests: 0
Past Year
  • Issues: 9
  • Pull requests: 7
  • Average time to close issues: about 1 month
  • Average time to close pull requests: about 1 month
  • Issue authors: 8
  • Pull request authors: 2
  • Average comments per issue: 1.22
  • Average comments per pull request: 0.0
  • Merged pull requests: 6
  • Bot issues: 0
  • Bot pull requests: 0
Top Authors
Issue Authors
  • DavisVaughan (13)
  • abdellah19jan (5)
  • twest820 (3)
  • HenrikBengtsson (3)
  • EvoLandEco (2)
  • elgabbas (2)
  • orgadish (1)
  • alex-lauer (1)
  • ramiromagno (1)
  • franrodalg (1)
  • wasdoff (1)
  • dicorynia (1)
  • gorkang (1)
  • alping (1)
  • angel-bee2018 (1)
Pull Request Authors
  • DavisVaughan (20)
  • HenrikBengtsson (5)
  • zeehio (1)
  • lionel- (1)
Top Labels
Issue Labels
breaking change :skull_and_crossbones: (3) 0.4.0 (3) reprex (2) documentation (1) bug (1) won't fix (1) feature (1) upkeep (1)
Pull Request Labels

Dependencies

DESCRIPTION cran
  • R >= 3.4.0 depends
  • future >= 1.25.0 depends
  • globals >= 0.14.0 imports
  • lifecycle >= 1.0.1 imports
  • purrr >= 0.3.4 imports
  • rlang >= 1.0.2 imports
  • vctrs >= 0.4.1 imports
  • carrier * suggests
  • covr * suggests
  • dplyr >= 0.7.4 suggests
  • knitr * suggests
  • listenv >= 0.6.0 suggests
  • magrittr * suggests
  • rmarkdown * suggests
  • testthat >= 3.0.0 suggests
  • tidyselect * suggests
  • withr * suggests
.github/workflows/R-CMD-check.yaml actions
  • actions/checkout v2 composite
  • r-lib/actions/check-r-package v2 composite
  • r-lib/actions/setup-pandoc v2 composite
  • r-lib/actions/setup-r v2 composite
  • r-lib/actions/setup-r-dependencies v2 composite
.github/workflows/pkgdown.yaml actions
  • JamesIves/github-pages-deploy-action 4.1.4 composite
  • actions/checkout v2 composite
  • r-lib/actions/setup-pandoc v2 composite
  • r-lib/actions/setup-r v2 composite
  • r-lib/actions/setup-r-dependencies v2 composite
.github/workflows/pr-commands.yaml actions
  • actions/checkout v2 composite
  • r-lib/actions/pr-fetch v2 composite
  • r-lib/actions/pr-push v2 composite
  • r-lib/actions/setup-r v2 composite
  • r-lib/actions/setup-r-dependencies v2 composite
.github/workflows/test-coverage.yaml actions
  • actions/checkout v2 composite
  • r-lib/actions/setup-r v2 composite
  • r-lib/actions/setup-r-dependencies v2 composite