In some processes, intermediate results force recalculation of earlier ones. Can the progressr
package support changes to the progression index during the calculation, so
I could report
step 1
step 2
step 3 oops, need to go back
step 2
step 3
step 4
done
Here’s some code that doesn’t work:
f <- function() {
p <- progressr::progressor(4)
i <- 0
while (i < 4) {
i <- i + 1
p(message = sprintf("at step %d", i))
if (i == 3 && runif(1) < 0.5) {
p(message = "Oops, need to go back")
i <- 2
}
Sys.sleep(1)
}
}
handlers(global = TRUE)
set.seed(123)
f()
It steps through from 1 to 4, then gives nothing, and a lot of warnings at the end.