Hi, I tried to add a progress bar to my script, but it seems the "txtProgressBar" function will wipe out what I want to print before it(for example - the "Hello" in following script), and the parameters "title" and "label" do not work either. How can I put a title for the progress bar? or is there any other better function I can use? testit <- function(total =20) { cat("Hello\n") # create progress bar pb <- txtProgressBar(min = 0, max = total, style = 3,title="ProgressBar1",label="ProgressBar2") for(i in 1:total){ Sys.sleep(0.1) # update progress bar setTxtProgressBar(pb, i) } close(pb) } testit() Best, Yunfei Li -------------------------------------------------------------------------------------- Research Assistant Department of Statistics & School of Molecular Biosciences Biotechnology Life Sciences Building 427 Washington State University Pullman, WA 99164-7520 Phone: 509-339-5096 http://www.wsu.edu/~ye_lab/people.html [[alternative HTML version deleted]]
Li, Yunfei wrote:> > Hi, > > I tried to add a progress bar to my script, but it seems the > "txtProgressBar" function will wipe out what I want to print before it(for > example - the "Hello" in following script), and the parameters "title" and > "label" do not work either. How can I put a title for the progress bar? or > is there any other better function I can use? > > testit <- function(total =20) > { > cat("Hello\n") > > # create progress bar > pb <- txtProgressBar(min = 0, max = total, style > 3,title="ProgressBar1",label="ProgressBar2") > for(i in 1:total){ > Sys.sleep(0.1) > # update progress bar > setTxtProgressBar(pb, i) > } > close(pb) > } > testit() >Are running your script in Mac OS X or Windows GUI? ?flush.console Replace cat(...) with cat("Hello\n"); flush.console() Berend -- View this message in context: http://r.789695.n4.nabble.com/A-question-about-txtProgressBar-function-tp3437902p3438040.html Sent from the R help mailing list archive at Nabble.com.
If your loop is producing its own output then you probably should not use txtProgressBar, but you can use either winProgressBar (if on windows) or tkProgressBar (on all platforms, but need tcltk package). These open an additional window with the progress bar and any additional information that you want, but does not do anything in the main console. -- Gregory (Greg) L. Snow Ph.D. Statistical Data Center Intermountain Healthcare greg.snow at imail.org 801.408.8111> -----Original Message----- > From: r-help-bounces at r-project.org [mailto:r-help-bounces at r- > project.org] On Behalf Of Li, Yunfei > Sent: Friday, April 08, 2011 6:04 PM > To: r-help at r-project.org > Subject: [R] A question about "txtProgressBar" function > > Hi, > > I tried to add a progress bar to my script, but it seems the > "txtProgressBar" function will wipe out what I want to print before > it(for example - the "Hello" in following script), and the parameters > "title" and "label" do not work either. How can I put a title for the > progress bar? or is there any other better function I can use? > > > > > testit <- function(total =20) > { > cat("Hello\n") > > # create progress bar > pb <- txtProgressBar(min = 0, max = total, style > 3,title="ProgressBar1",label="ProgressBar2") > for(i in 1:total){ > Sys.sleep(0.1) > # update progress bar > setTxtProgressBar(pb, i) > } > close(pb) > } > > > testit() > > > > Best, > > Yunfei Li > ----------------------------------------------------------------------- > --------------- > Research Assistant > Department of Statistics & > School of Molecular Biosciences > Biotechnology Life Sciences Building 427 > Washington State University > Pullman, WA 99164-7520 > Phone: 509-339-5096 > http://www.wsu.edu/~ye_lab/people.html > > > [[alternative HTML version deleted]] > > ______________________________________________ > 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.
Seemingly Similar Threads
- txtProgressBar examples?
- Strange behavior when using progress bar (Fwd: Re: [R] The code itself disappears after starting to execute the for loop)
- Strange behavior when using progress bar (Fwd: Re: [R] The code itself disappears after starting to execute the for loop)
- How to update R?
- In svm(), how to connect quantitative prediction result to categorical result?