[Rcpp-devel] progress bar in for loop

baptiste auguie baptiste.auguie at googlemail.com
Sun Aug 8 16:37:16 CEST 2010


Dear list,

There's one feature that I miss after porting a for loop from R to C++
: the possibility to add a progress bar. I used to write,

library(plyr)
l_ply(seq(1,10), function(ii) Sys.sleep(0.2), .progress = "text")

My naive attempt in C++ was unsuccessful,

using namespace std;

  cout << "["; //start progress bar
  for(ll=0; ll<N; ll++){ // loop over some variable
    if ( !( ((ll+1)*100/N) % 5) ) //  display a character every 5 steps
      cout << "=";
  }
  cout << "["; //stop progress bar

For some reason (compiler?) nothing is displayed until the end of the
execution, where the full text is suddenly displayed at once. Is there
a workaround?

Best regards,

baptiste


More information about the Rcpp-devel mailing list