Purrr, future, and printing

I'm using the future package to parallelize some code being used with pmap, and the speedup is fantastic. The only thing I'm missing is a way to print an indication of progress, i.e., what slice of the tibble is being worked on. Functions sent to future() don't seem to be able to return anything to the R console, so I'm at a loss as to how I might indicate progress. Any tips or tricks I can use here?

A reprex that demonstrates what I'm after:

rm(list = ls())

library(magrittr)
library(tidyverse)
library(future)

some.function <- function(a, b) {
  print(sprintf('printing: %s %s', a, b))
}

my.tibble <- tibble(
  one = letters[1:3],
  two = LETTERS[1:3]
)

# standard serial evaluation: prints as expected. Something like this would be helpful.
result <- my.tibble %>%
  mutate(test = pmap(list(one, two), some.function))

# parallel evaluation: no printing?
# Though the result of print() is returned as a side effect 
plan(multiprocess)
result <- my.tibble %>%
  mutate(
    test = pmap(list(one, two), ~future(some.function(..1, ..2))),
    test = map(test, values)
  )
1 Like

Not a solution, but see Issue #149:

The furrr package is a wrapper around purrr and future and aims to provide a progress bar.

1 Like