Skip to content
Prev 78690 / 398502 Next

Show Progress in loop

Hello,

You must explicitly use print(), show() on an object -here, use 
print(i)- in a loop or alternatively, use cat() to display string like:
cat("loop", i, "\n")

With RGui under Windows, there is another subtility: if you have turn on 
'Misc -> Buffered output' (it is ON by default), all output are delayed 
until the end of the command processing. You need to use flush.console() 
to tell to print i immediatelly within a loop. The best synthax is 
(since the command is only usable under Windows):
 > for (i in 1:10) {
 >	print(i)	# You must use print explicitly within a loop
 >	# or, better, use: cat("loop", i, "\n")
 >	# Next command is to overcome buffered output in RGui
 >	if (.Platform$OS.type == "windows") flush.console()
 >	# Next command simulates a "long" process (taking 1 sec)
 >	Sys.sleep(1)
 >	# ... your loop code here...
 > }

Alternatively, you can use the progress() function in svMisc package 
(SciViews bundle). Load svMisc and look at its online help... you have 
several examples of use.
 > library(svMisc)
 > ?progress

Best,

Philippe Grosjean

..............................................<??}))><........
  ) ) ) ) )
( ( ( ( (    Prof. Philippe Grosjean
  ) ) ) ) )
( ( ( ( (    Numerical Ecology of Aquatic Systems
  ) ) ) ) )   Mons-Hainaut University, Pentagone (3D08)
( ( ( ( (    Academie Universitaire Wallonie-Bruxelles
  ) ) ) ) )   8, av du Champ de Mars, 7000 Mons, Belgium
( ( ( ( (
  ) ) ) ) )   phone: + 32.65.37.34.97, fax: + 32.65.37.30.54
( ( ( ( (    email: Philippe.Grosjean at umh.ac.be
  ) ) ) ) )
( ( ( ( (    web:   http://www.umh.ac.be/~econum
  ) ) ) ) )          http://www.sciviews.org
( ( ( ( (
..............................................................
Rainer M. Krug wrote: