How to make a progress bar in R

March 19, 2009
76 Views

If you’re writing a function that you expect to take a long time to complete, you might want to give feedback to the user (or even just to yourself, during the development phase) that the function is actually still running and hasn’t simply hung. The obvious solution is to include a statement like cat(iter/totaliters,”% complete…”) in the loop. However, if you’re using anything other than the console version of R, the R GUI will hold any such output until the function completes, defeating the purpose. Mark Heckmann explains how you can turn off this “console buffering” feature so that you…

If you’re writing a function that you expect to take a long time to complete, you might want to give feedback to the user (or even just to yourself, during the development phase) that the function is actually still running and hasn’t simply hung.  The obvious solution is to include a statement like

cat(iter/totaliters,”% complete…”)

in the loop. However, if you’re using anything other than the console version of R, the R GUI will hold any such output until the function completes, defeating the purpose. Mark Heckmann explains how you can turn off this “console buffering” feature so that you can see the progress output.  But then he goes one better: how about building a graphical progress bar?  See his post for a neat example of building such GUI elements with Tcl/Tk.