Quantcast
Channel: Active questions tagged r - Stack Overflow
Viewing all articles
Browse latest Browse all 201867

Progress bar within drake functions

$
0
0

I'm trying to implement progress bars within function for use in a drake-r project. I am using the progress package for the progress_bar R6 class. The following example produces the expected progress bar:

library(dplyr)
library(purrr)
library(progress)

data <- mtcars %>%
    split(.$carb)

n <- length(data)

pb <- progress::progress_bar$new(total = n)

data <- data %>%
    map(~{pb$tick()
      Sys.sleep(2)
      lm(mpg ~ wt, data = .x)
      })

If I put this into my drake workflow, a new progress bar displays for each iteration:

fit_lm <- function() {
  data <- mtcars %>%
    split(.$carb)

  n <- length(data)

  pb <- progress::progress_bar$new(total = n)

  data <- data %>%
    map(~{pb$tick()
      Sys.sleep(2)
      lm(mpg ~ wt, data = .x)
      })

  return(data)
}

plan <- drake_plan(
  models = fit_lm()
)

make(plan)

Console output: enter image description here

How can I modify the function to display only one progress bar that updates on each iteration?


Viewing all articles
Browse latest Browse all 201867

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>