# Purrring progress bars (adding a progress bar to purrr::map)

With all the functional programming going on (i.e., purrr::map and the likes), there is at least one thing that I found missing: progress bars. The plyr::do function had a nice looking progress bar open up by default if the operation took more than 2 seconds and had at least two more to go (as per Hadley’s description in Issue#149 in tidyverse/purrr).

The issue is still open, for the time of writing these lines, and will probably be solved sometime in the near future as a feature of purrr::map.

Personally, I like @cderv’s elegent solution suggested at that same github issue.

Here is an example implementation for reading multiple files within a directory and combining them into a single tibble while showing a progress bar when reading the files. The file reading is very similar to what was suggested in this post.

library(purrr)
library(dplyr)

# directory from which to read a bunch of files (the example here uses csv)
file_list <- dir(path = "PATH_TO_DIRECTORY", pattern = ".csv")

# define reading function which includes the progress bar updates and printing
pb$tick()$print()
map_df(~read_with_progress(.))
|=====================================           |80% ~23 s remaining