Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Repeat printing bars in terminal when width is specified #20

Closed
renkun-ken opened this issue Jun 4, 2015 · 3 comments
Closed

Repeat printing bars in terminal when width is specified #20

renkun-ken opened this issue Jun 4, 2015 · 3 comments

Comments

@renkun-ken
Copy link

library(progress)

pb <- progress_bar$new(format = "processing [:bar] :percent :elapsed | :eta",
    total = 100, width = 80)

for (i in 1:100) {
  pb$tick()
  Sys.sleep(1 / 100)
}

If I run the code in RStudio, there's no problem at all. But if I run the code with rscript in terminal, then the progress bar is repeatedly printed out like

progress-terminal

As long as I remove width argument, the problem is gone.

Here's my session info:

R version 3.2.0 (2015-04-16)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 8 x64 (build 9200)

locale:
[1] LC_COLLATE=English_United States.1252  LC_CTYPE=English_United States.1252   
[3] LC_MONETARY=English_United States.1252 LC_NUMERIC=C                          
[5] LC_TIME=English_United States.1252    

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

other attached packages:
[1] progress_1.0.1

loaded via a namespace (and not attached):
 [1] magrittr_1.5      assertthat_0.1    R6_2.0.1          rversions_1.0.0   prettyunits_1.0.0
 [6] tools_3.2.0       rstudioapi_0.3.1  RCurl_1.95-4.6    memoise_0.2.1     git2r_0.10.1     
[11] digest_0.6.8      bitops_1.0-6      devtools_1.8.0    XML_3.98-1.2     
@gaborcsardi
Copy link
Member

I guess this is because your screen is 80 characters wide. In this case you can only set width to 79 or less, otherwise the cursor moves to the next line, and a \r will not move it back to the previous line.

This is why width is set to getOption("width") - 2 by default. Technically minus one should be enough as well.

@gaborcsardi
Copy link
Member

Please reopen if you still have problems.

@renkun-ken
Copy link
Author

Your explanation perfectly solves my problem. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants