File: progress.R

package info (click to toggle)
r-bioc-biocparallel 1.40.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,768 kB
  • sloc: cpp: 139; sh: 14; makefile: 8
file content (42 lines) | stat: -rw-r--r-- 1,408 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
### =========================================================================
### progress bar 
### -------------------------------------------------------------------------

.progress <- function(style = 3, active = TRUE, iterate = FALSE, ...) {

    if (active) {
        ntasks <- 0L
        if (iterate) {
            list(init = function(x) {
                message("iteration: ", appendLF=FALSE)
            }, step = function(n) {
                ntasks <<- ntasks + 1L
                erase <- paste(rep("\b", ceiling(log10(ntasks))), collapse="")
                message(erase, ntasks, appendLF = FALSE)
            }, term = function() {
                message()               # new line
            })
        } else {
            ## derived from plyr::progress_text()
            txt <- NULL
            max <- 0
            list(init = function(x) {
                txt <<- txtProgressBar(max = x, style = style, ...)
                setTxtProgressBar(txt, 0)
                max <<- x
            }, step = function(n) {
                ntasks <<- ntasks + n
                setTxtProgressBar(txt, ntasks)
                if (ntasks == max) cat("\n")
            }, term = function() {
                close(txt)
            })
        }
    } else {
        list(
            init = function(x) NULL,
            step = function(n) NULL,
            term = function() NULL
        )
    }
}