0

How do you get a function to return silently, INCLUDING POSSIBLE PROGRESS BARS???

I found this question: Make a function return silently and tested the suggested answer to use invisible(), but invisible() does not work for hiding text progress bars within functions!

Example function below:

myfun <- function(a){
  pb <- txtProgressBar(min=0, max=a, initial=0, style=3)
  foreach(b=1:a)%do%{
    Sys.sleep(1/20)
    setTxtProgressBar(pb, b)
  }
}
###Shows the progress bar
myfunout1 <- invisible(myfun(30))

###Still shows the progress bar
invisible(myfunout1 <- myfun(30))
Ronak Shah
  • 355,584
  • 18
  • 123
  • 178
Neal Barsch
  • 2,026
  • 9
  • 35
  • If you type`invisible(myfun(30))` in the console, you may see that it does not return an object. It does print the progress bar on the screen. – Suren Mar 15 '18 at 06:04
  • maybe you are after something like `sink` – Suren Mar 15 '18 at 06:05
  • `txtProgressBar` uses `cat`, so the top couple answers at the dupe seem good. I'm a little more skeptical of Sacha's answer - I'd stick with the `sink` or `capture.output` methods. – Gregor Thomas Mar 15 '18 at 06:05
  • @Suren, yes that is what I am trying to avoid is the progress bar on the screen – Neal Barsch Mar 15 '18 at 06:06

0 Answers0