title: Progress bar in command-line R
body: <p>I am attempting to use a progress bar in an R script for command-line, however it only shows 0%. Please consider the following working example:</p>
  
  <pre><code> testit &lt;- function(x = sort(runif(20)), ...)
   {
       pb &lt;- txtProgressBar(...)
       for(i in c(0, x, 1)) {Sys.sleep(0.5); setTxtProgressBar(pb, i)}
       Sys.sleep(1)
       close(pb)
   }
   testit()
   testit(runif(10))
   testit(style = 3)
  </code></pre>
  
  <p>My code, however, does not work accordingly, and I am failing to identify my error:</p>
  
  <pre><code>  dep=c("data.table", "docopt")
    for (i in dep){
      pb &lt;- txtProgressBar(min = 0, max = length(dep), style = 3)
      if (i %in% installed.packages()){
        library(i, character.only = TRUE)
      } else {
        install.packages(i, repos="http://cran.rstudio.com/", dependencies = T)
        library(i, character.only = TRUE)
      }
      setTxtProgressBar(pb, i)
    }
    close(pb)
  </code></pre>
  
  <ul>
  <li>How to make the progress bar actually progress in the latter?</li>
  </ul>