These functions work exactly the same as map_vec(), map2_vec(), pmap_vec(), imap_vec() and xmap_vec(), but allow you to map in parallel.

future_map_vec(
  .x,
  .f,
  ...,
  .class = NULL,
  .progress = FALSE,
  .options = furrr::furrr_options()
)

future_map2_vec(
  .x,
  .y,
  .f,
  ...,
  .class = NULL,
  .progress = FALSE,
  .options = furrr::furrr_options()
)

future_pmap_vec(
  .l,
  .f,
  ...,
  .class = NULL,
  .progress = FALSE,
  .options = furrr::furrr_options()
)

future_imap_vec(
  .x,
  .f,
  ...,
  .class = NULL,
  .progress = FALSE,
  .options = furrr::furrr_options()
)

future_xmap_vec(
  .l,
  .f,
  ...,
  .class = NULL,
  .progress = FALSE,
  .options = furrr::furrr_options()
)

Arguments

.x

A list or atomic vector.

.f

A function, formula, or vector (not necessarily atomic).

If a function, it is used as is.

If a formula, e.g. ~ .x + 2, it is converted to a function. There are three ways to refer to the arguments:

  • For a single argument function, use .

  • For a two argument function, use .x and .y

  • For more arguments, use ..1, ..2, ..3 etc

This syntax allows you to create very compact anonymous functions.

If character vector, numeric vector, or list, it is converted to an extractor function. Character vectors index by name and numeric vectors index by position; use a list to index by position and name at different levels. If a component is not present, the value of .default will be returned.

...

Additional arguments passed on to .f

.class

If .class is specified, all

.progress

A single logical. Should a progress bar be displayed? Only works with multisession, multicore, and multiprocess futures. Note that if a multicore/multisession future falls back to sequential, then a progress bar will not be displayed.

Warning: The .progress argument will be deprecated and removed in a future version of furrr in favor of using the more robust progressr package.

.options

The future specific options to use with the workers. This must be the result from a call to furrr_options().

.y

A vector the same length as .x. Vectors of length 1 will be recycled.

.l

A list of vectors, such as a data frame. The length of .l determines the number of arguments that .f will be called with. List names will be used if present.

Value

Equivalent to map_vec(), map2_vec(), pmap_vec(), imap_vec() and xmap_vec()

Examples

fruits   <- c("apple", "banana", "carrot", "durian", "eggplant")
desserts <- c("bread", "cake", "cupcake", "streudel", "muffin")
x        <- sample(5)
y        <- sample(5)
z        <- sample(5)
names(z) <- fruits

future_map_vec(x, ~ . ^ 2)
#> ! `future_map_vec()()` is not set up to run background processes.
#>  Try running `future::plan("multisession")`.
#>  Check `help(plan, future)` for more details.
#> 
#> Attaching package: ‘purrr’
#> The following objects are masked from ‘package:crossmap’:
#> 
#>     map2_vec, map_vec, pmap_vec
#> [1]  1  9 25  4 16
future_map_vec(fruits, paste0, "s")
#> ! `future_map_vec()()` is not set up to run background processes.
#>  Try running `future::plan("multisession")`.
#>  Check `help(plan, future)` for more details.
#> [1] "apples"    "bananas"   "carrots"   "durians"   "eggplants"

future_map2_vec(x, y, ~ .x + .y)
#> ! `future_map2_vec()()` is not set up to run background processes.
#>  Try running `future::plan("multisession")`.
#>  Check `help(plan, future)` for more details.
#> [1] 3 8 9 5 5
future_map2_vec(fruits, desserts, paste)
#> ! `future_map2_vec()()` is not set up to run background processes.
#>  Try running `future::plan("multisession")`.
#>  Check `help(plan, future)` for more details.
#> [1] "apple bread"     "banana cake"     "carrot cupcake"  "durian streudel"
#> [5] "eggplant muffin"

future_pmap_vec(list(x, y, z), sum)
#> ! `future_pmap_vec()()` is not set up to run background processes.
#>  Try running `future::plan("multisession")`.
#>  Check `help(plan, future)` for more details.
#> [1]  4 12 11  8 10
future_pmap_vec(list(x, fruits, desserts), paste)
#> ! `future_pmap_vec()()` is not set up to run background processes.
#>  Try running `future::plan("multisession")`.
#>  Check `help(plan, future)` for more details.
#> [1] "1 apple bread"     "3 banana cake"     "5 carrot cupcake" 
#> [4] "2 durian streudel" "4 eggplant muffin"

future_imap_vec(x, ~ .x + .y)
#> ! `future_imap_vec()()` is not set up to run background processes.
#>  Try running `future::plan("multisession")`.
#>  Check `help(plan, future)` for more details.
#> [1] 2 5 8 6 9
future_imap_vec(x, ~ paste0(.y, ": ", .x))
#> ! `future_imap_vec()()` is not set up to run background processes.
#>  Try running `future::plan("multisession")`.
#>  Check `help(plan, future)` for more details.
#> [1] "1: 1" "2: 3" "3: 5" "4: 2" "5: 4"
future_imap_vec(z, paste)
#> ! `future_imap_vec()()` is not set up to run background processes.
#>  Try running `future::plan("multisession")`.
#>  Check `help(plan, future)` for more details.
#>        apple       banana       carrot       durian     eggplant 
#>    "1 apple"   "4 banana"   "2 carrot"   "3 durian" "5 eggplant" 

future_xmap_vec(list(x, y), ~ .x * .y)
#> ! `future_xmap_vec()()` is not set up to run background processes.
#>  Try running `future::plan("multisession")`.
#>  Check `help(plan, future)` for more details.
#> ! `future_xmap()()` is not set up to run background processes.
#>  Try running `future::plan("multisession")`.
#>  Check `help(plan, future)` for more details.
#>  [1]  2  6 10  4  8  5 15 25 10 20  4 12 20  8 16  3  9 15  6 12  1  3  5  2  4
future_xmap_vec(list(fruits, desserts), paste)
#> ! `future_xmap_vec()()` is not set up to run background processes.
#>  Try running `future::plan("multisession")`.
#>  Check `help(plan, future)` for more details.
#> ! `future_xmap()()` is not set up to run background processes.
#>  Try running `future::plan("multisession")`.
#>  Check `help(plan, future)` for more details.
#>  [1] "apple bread"       "banana bread"      "carrot bread"     
#>  [4] "durian bread"      "eggplant bread"    "apple cake"       
#>  [7] "banana cake"       "carrot cake"       "durian cake"      
#> [10] "eggplant cake"     "apple cupcake"     "banana cupcake"   
#> [13] "carrot cupcake"    "durian cupcake"    "eggplant cupcake" 
#> [16] "apple streudel"    "banana streudel"   "carrot streudel"  
#> [19] "durian streudel"   "eggplant streudel" "apple muffin"     
#> [22] "banana muffin"     "carrot muffin"     "durian muffin"    
#> [25] "eggplant muffin"