Adding progress bar to replicate function in R

Viewed 1358

I am using replicate to run my own analyse function multiple times (analyse returns a list):

results <- replicate(reps, analyse())

Is there a way to add progress bar, showing the percentage of replications finished at the moment? I have tried with txtProgressBar, but don't know how to make it work without a for-loop.

EDIT: reproducible example of replicate:

analyse <- function() {
  out <- list('a' = vector('list', 5), 'b' = vector('list', 5))
}
results <- replicate(3, analyse())

In my case, output of analyse is a deep list of lists with results. I would like the progress bar to update every time a new column of results is filled in, so after each replication.

2 Answers

The solution is to use pbreplicate() function from pbapply package. This package also contains respective progress bar functions for apply(), lapply() and sapply().

Related