title: Wrapper to FOR loops with progress bar
body: <p>I like to use a progress bar while running slow <code>for</code> loops. This could be done easily with several helpers, but I do like the <code>tkProgressBar</code> from <em>tcltk</em> package.</p>
  
  <p>A small example:</p>
  
  <pre><code>pb &lt;- tkProgressBar(title = "Working hard:", min = 0, max = length(urls), width = 300)
  for (i in 1:300) {
      # DO SOMETHING
      Sys.sleep(0.5)
      setTkProgressBar(pb, i, label=paste( round(i/length(urls)*100, 0), "% ready!"))
  }
  close(pb)
  </code></pre>
  
  <p>And I would like to set up a small function to store in my <em>.Rprofile</em> named to <code>forp</code> (as: for loop with progressbar), to call just like <code>for</code> but with auto added progress bar - but unfortunately have no idea how to implement and grab the <code>expr</code> part of the loop function. I had some experiments with <code>do.call</code> but without success :(</p>
  
  <p>Imaginary working example (which acts like a <code>for</code> loop but creates a <code>TkProgressBar</code> and auto updates it in each iteration):</p>
  
  <pre><code>forp (i in 1:10) {
      #do something
  }
  </code></pre>
  
  <p><strong>UPDATE</strong>: I think the core of the question is how to write a function which not only has parameters in the parentheses after the function (like: <code>foo(bar)</code>), but also can handle <code>expr</code> specified after the closing parentheses, like: <code>foo(bar) expr</code>.</p>
  
  <hr>
  
  <p><strong>BOUNTY OFFER</strong>: would go to any answer that could modify <a href="https://stackoverflow.com/questions/7349570/wrapper-to-for-loops-with-progress-bar/7354293#7354293">my suggested function</a> to work like the syntax of basic <code>for</code> loops. E.g. instead of</p>
  
  <pre><code>&gt; forp(1:1000, {
  +   a&lt;-i
  + })
  &gt; a
  [1] 1000
  </code></pre>
  
  <p>it could be called like:</p>
  
  <pre><code>&gt; forp(1:1000) {
  +   a&lt;-i
  + }
  &gt; a
  [1] 1000
  </code></pre>
  
  <p><strong>Just to clarify the task again</strong>: how could we grab the <code>{ expression }</code> part of a function call? I am afraid that this is not possible, but will leave on the bounty for a few days for the pros :)</p>