The “future_pmap” Function in R

  • Package: furrr

  • Purpose: Parallel mapping using futures with multiple arguments.

  • General class: Parallel computing

  • Required argument(s):

    • .f: The function to be applied to each element.

    • ...: The input data, is specified as individual arguments in a list.

  • Notable optional arguments:

    • None

  • Example:

  • # Load the furrr package
    library(furrr)

    # Tells future_pmap to run in parallel on 2 cores
    plan(multisession, workers = 2)

    # Define a function that takes multiple arguments
    add_numbers <- function(a, b) {return(a + b)}

    # Use future_pmap to apply the function in parallel with multiple arguments
    result <- future_pmap(list(a = c(1, 2, 3), b = c(4, 5, 6)), .f = add_numbers)

    # Print the result
    print(result)

  • In this example, we use the “future_pmap” function from the furrr package to apply the add_numbers function to pairs of elements in parallel. The function add_numbers takes two arguments a and b, and we provide lists of values for a and b to future_pmap. The output result will contain the sum of corresponding elements from the input lists.

Previous
Previous

The “future_map2” Function in R

Next
Next

The “future_map” Function in R