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))