[R] setTxtProgressBar clearing console (Windows RGui)

Jon Skoien jon.skoien at jrc.ec.europa.eu
Wed Sep 16 16:45:21 CEST 2015

I have frequently noticed a strange effect when using the progress bar 
in a loop, that the console will sometimes be cleared. Whatever was 
printed before will then be inaccessible, which can be annoying when I 
want to check the progress and possible issues in a long script. It 
seems to be an intermittent problem, so it could also be related to my 
computer or other software running. I have had this issue in several R 
versions, and managed to provoke it in 3.2.2 with the following:

testit <- function(x = 100, ...)
     pb <- txtProgressBar(0, x, ...)
     for(i in 0:x) {Sys.sleep(0.1); setTxtProgressBar(pb, i)}

for (i in 1:1000) {
   testit(style = 3)

The printing is just to fill up the console quicker, as the clearing 
seems to occur more frequent then. However, the loop above can sometimes 
call testit 5-30 times before the console is cleared again. In my real 
script the console is usually cleared more frequent.
With x = 10 above, it seems not to clear the console, at least not for a 
long time.

Does anyone have a clue why this happens, or if something can be done to 
prevent it? Is it reproducible, or something that only bothers me?


 > sessionInfo()
R version 3.2.2 (2015-08-14)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 8 x64 (build 9200)

[1] LC_COLLATE=English_United States.1252
[2] LC_CTYPE=English_United States.1252
[3] LC_MONETARY=English_United States.1252
[5] LC_TIME=English_United States.1252

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base

Jon Olav Skøien
Joint Research Centre - European Commission
Institute for Environment and Sustainability (IES)
Climate Risk Management Unit

Via Fermi 2749, TP 100-01,  I-21027 Ispra (VA), ITALY

jon.skoien at jrc.ec.europa.eu
Tel:  +39 0332 789205

Disclaimer: Views expressed in this email are those of the individual 
and do not necessarily represent official views of the European Commission.

More information about the R-help mailing list