Debian Codegraph @

R/progress.R

raw
1
2 renv_progress_create <- function(max, wait = 1.0) {
3
4 # local variables for closure
5 count <- 0L
6 max <- max
7 message <- ""
8 start <- Sys.time()
9
10 function() {
11
12 # check for and print progress
13 count <<- count + 1L
14
15 # if not enough time has elapsed yet, nothing to do
16 if (Sys.time() - start < wait)
17 return()
18
19 # create message
20 backspaces <- paste(rep("\b", nchar(message)), collapse = "")
21 message <<- sprintf("[%i/%i] ", count, max)
22 all <- paste(backspaces, message, sep = "")
23 cat(all, file = stdout(), sep = "")
24
25 }
26
27 }
28
29 renv_progress_callback <- function(callback, max, wait = 1.0) {
30 tick <- renv_progress_create(max, wait)
31 function(...) { tick(); callback(...) }
32 }