Hello all, I am using Rprintf in a C for loop (from .Call) to print a progress indicator showing the current percent complete. The loop I am doing is an time intensive call to another function. I have noticed that Rprintf does not print to the R-window until the entire loop has been completed. When it reaches the end of the loop it suddenly prints 0 percent to 100 percent in a split second. For less intensive function calls it prints properly while looping. My question is this: is there any way to force Rprintf to print to the screen during a loop? On a related note, how can I show a percent sign in the output? For example, Rprintf("0%"); only prints a zero. Thanks!, Erik
Erik Wright wrote:> > Hello all, > > I am using Rprintf in a C for loop (from .Call) to print a progress > indicator showing the current percent complete. The loop I am doing is an > time intensive call to another function. I have noticed that Rprintf does > not print to the R-window until the entire loop has been completed. When > it reaches the end of the loop it suddenly prints 0 percent to 100 percent > in a split second. For less intensive function calls it prints properly > while looping. My question is this: is there any way to force Rprintf to > print to the screen during a loop? > > On a related note, how can I show a percent sign in the output? For > example, Rprintf("0%"); only prints a zero. > > Thanks!, > Erik >Perhaps you could use a callback to R's built in progress bar functions to perform this for you in a nicely formatted way. Something of the form: pBar <- txtProgressBar( min = , max = , type = 3 ) cResults <- .Call( 'some_c_routine', some, args, including, pBar ) close( pBar ) Since you pass the progress bar to the C routine, you could perform a callback to the R function setTxtProgressBar() to update it every iteration. I posted an example of how to perform callbacks from C to R in this thread: http://n4.nabble.com/Writing-own-simulation-function-in-C-td1580190.html#a1580423 Hope this helps! -Charlie ----- Charlie Sharpsteen Undergraduate-- Environmental Resources Engineering Humboldt State University -- View this message in context: http://n4.nabble.com/Rprintf-not-updating-tp1751703p1751725.html Sent from the R help mailing list archive at Nabble.com.
> -----Original Message----- > From: r-help-bounces at r-project.org > [mailto:r-help-bounces at r-project.org] On Behalf Of Erik Wright > Sent: Monday, April 05, 2010 7:59 AM > To: r-help at r-project.org > Subject: [R] Rprintf not updating > > Hello all, > > I am using Rprintf in a C for loop (from .Call) to print a > progress indicator showing the current percent complete. The > loop I am doing is an time intensive call to another > function. I have noticed that Rprintf does not print to the > R-window until the entire loop has been completed. When it > reaches the end of the loop it suddenly prints 0 percent to > 100 percent in a split second. For less intensive function > calls it prints properly while looping. My question is this: > is there any way to force Rprintf to print to the screen > during a loop?If you are using the Windows GUI for R hit control-W or toggle the Misc\OutputBuffering menu item.> On a related note, how can I show a percent sign in the > output? For example, Rprintf("0%"); only prints a zero.Use %%. Bill Dunlap Spotfire, TIBCO Software wdunlap tibco.com> > Thanks!, > Erik > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >