Skip to content

Instantly share code, notes, and snippets.

@andrie
Created October 21, 2015 10:08
Show Gist options
  • Save andrie/5b4ec4aa39130d8e8b84 to your computer and use it in GitHub Desktop.
Save andrie/5b4ec4aa39130d8e8b84 to your computer and use it in GitHub Desktop.
Progress bars with foreach and doSNOW
library(doSNOW)
library(tcltk)
cl <- makeSOCKcluster(2)
registerDoSNOW(cl)
pb <- txtProgressBar(max=100, style=3)
progress <- function(n) setTxtProgressBar(pb, n)
opts <- list(progress=progress)
r <- foreach(i=1:100, .options.snow=opts) %dopar% {
Sys.sleep(1)
sqrt(i)
}
close(pb)
@thiagoveloso
Copy link

Hi @andrie, thanks for sharing this. Would it be possible to do the same using doParallel rather than doSNOW?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment