Progress bar in purrr::map_df
I like the purrr collection of functions rather than the base R equivalents. But when working with big datasets, it is helpful to have some indication of how long an operation is going to take.
This simple function creates a version of purrr's map_df
function but with an added progress bar. It requires the progress package to be installed.
map_df_progress <- function(.x, .f, ..., .id = NULL) {
.f <- purrr::as_mapper(.f, ...)
pb <- progress::progress_bar$new(total = length(.x), force = TRUE)
f <- function(...) {
pb$tick()
.f(...)
}
purrr::map_df(.x, f, ..., .id = .id)
}