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
  • 377,200
  • 20
  • 156
  • 213
Neal Barsch
  • 2,810
  • 2
  • 13
  • 39

0 Answers0