title: R: Where to place winprogressbar code in an existing loop?
body: <p>I would like to add a progress bar to my script in R, but I'm not sure where to put this in my loop. The code for the winProgressbar is below from the internet. Where should I place this code in my loop?</p>
  
  <p>Thanks!</p>
  
  <p>pb &lt;- winProgressBar(title = "progress bar", min = 0,
                        max = total, width = 300)</p>
  
  <pre><code>for(i in 1:total){
   Sys.sleep(0.1)
   setWinProgressBar(pb, i, title=paste( round(i/total*100, 0),
                                         "% done"))
   }
   close(pb)
  </code></pre>