Skip to content

Instantly share code, notes, and snippets.

@thierrymoudiki
Forked from andrie/doSNOW.R
Created October 3, 2025 07:31
Show Gist options
  • Save thierrymoudiki/54f7c6a220270eb7ca2ffdd7816aa46f to your computer and use it in GitHub Desktop.
Save thierrymoudiki/54f7c6a220270eb7ca2ffdd7816aa46f 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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment