Crops
Crops

Reputation: 5154

R text progress bar inessential output

I am trying to use a text progress bar in an R function as follows.

pb <- txtProgressBar(min = 0, max = 10, style = 3)

for (i in 1:10) {
Sys.sleep(0.25)
setTxtProgressBar(pb, i)
}

I get an unnecessary line of output as follows with style 3, when initiating the progress bar.

pb <- txtProgressBar(min = 0, max = 10, style = 3)
  |                                                                       |   0%

Is there anyway to avoid this? invisible does not seem to work. With other style 1 and 2 such an output in ablesnt.

Upvotes: 2

Views: 345

Answers (1)

James
James

Reputation: 66844

If you use invisible after using capture.output you can avoid any output:

invisible(capture.output(pb <- txtProgressBar(min = 0, max = 10, style = 3)))

Upvotes: 1

Related Questions