progressbar with the doMC package?

Created on 18 Apr 2016  ·  3Comments  ·  Source: r-lib/progress

Is the progress package also suitable for the doMC package?

Most helpful comment

Or the parallel package? If not, +1 for this feature.

All 3 comments

Or the parallel package? If not, +1 for this feature.

I am not sure what it would take to implement this, to be honest. E.g. for parallel, one would need parallel to communicate back, how much of the work has been done already. Is that even possible?

@gaborcsardi I did some searching and the following is what I've found:

library("foreach")
library("doParallel")
library("progress")

registerDoParallel(parallel::makeCluster(7, outfile = ""))

pb <- progress_bar$new(
            format = " [:bar] :percent in :elapsed",
            total = 30, clear = FALSE, width = 80, force = T)
a <- foreach (i  = 1:30) %dopar% {
    pb$tick()
    Sys.sleep(0.5)
}


pb <- txtProgressBar(title = "Iterative training", min = 0, max = 30, style = 3)

foreach (i  = 1:30) %dopar% {
    setTxtProgressBar(pb, i)
    Sys.sleep(0.5)
}

stopCluster(cl)

The txtProgressBar only works when the stype is 2 or 3. According to the function's manual:

style = 1 and style = 2 just shows a line of char. They differ in that style = 2 redraws the line each time, which is useful if other code might be writing to the R console. style = 3 marks the end of the range by | and gives a percentage to the right of the bar.

I think the reason txtProgressBar works is because the outfile = "" exists while making the cluster.

I think mimicking what txtProgressBar does for style 2 would solve this.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

gaborcsardi picture gaborcsardi  ·  7Comments

pssguy picture pssguy  ·  20Comments

hadley picture hadley  ·  9Comments

dougmitarotonda picture dougmitarotonda  ·  8Comments

hudon picture hudon  ·  4Comments