Aliases: TextStatusBar
Keywords: classes programming IO
### ** Examples # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # Read all HTML files in the base package # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - path <- system.file(package="base") files <- list.files(path, recursive=TRUE, full.names=TRUE) files <- files[sapply(files, FUN=isFile)] nfiles <- length(files) cat(sprintf("Reading %d files in %s:\n", nfiles, path))
Reading 24 files in /usr/local/R/4.2/library/base:
# Create a status bar with four labels sb <- TextStatusBar("File: %-*s [%3.0f%% %7.0f bytes %-8s]", hfill=1, file="", progress=0, nbytes=0L, time="") nbytes <- 0L for (kk in seq_len(nfiles)) { file <- files[kk] # Update the status bar if (sb) { setLabel(sb, "progress", 100*kk/nfiles) if (kk %% 10 == 1 || kk == nfiles) setLabel(sb, "file", substr(basename(file), 1, 44)) size <- file.info(file)$size # popMessage() calls update() too popMessage(sb, sprintf("Processing %s (%.2fkB)", basename(file), size/1024)) flush(sb) } # Read the file bfr <- readBin(file, what="raw", n=size) nbytes <- nbytes + size # Emulate a slow process if (interactive()) Sys.sleep(rexp(1, rate=60)) # Update the status bar if (sb) { setLabel(sb, "nbytes", nbytes) setLabel(sb, "time", format(Sys.time(), "%H:%M:%S")) update(sb) } }
Processing CITATION (0.93kB) File: CITATION [ 4% 0 bytes ]File: CITATION [ 4% 956 bytes 15:55:00] Processing error.catching.R (1.15kB) File: CITATION [ 8% 956 bytes 15:55:00]File: CITATION [ 8% 2135 bytes 15:55:00] Processing is.things.R (4.69kB) File: CITATION [ 12% 2135 bytes 15:55:00]File: CITATION [ 12% 6933 bytes 15:55:00] Processing recursion.R (2.07kB) File: CITATION [ 17% 6933 bytes 15:55:00]File: CITATION [ 17% 9048 bytes 15:55:00] Processing scoping.R (1.52kB) File: CITATION [ 21% 9048 bytes 15:55:00]File: CITATION [ 21% 10608 bytes 15:55:00] Processing DESCRIPTION (0.35kB) File: CITATION [ 25% 10608 bytes 15:55:00]File: CITATION [ 25% 10962 bytes 15:55:00] Processing aliases.rds (12.21kB) File: CITATION [ 29% 10962 bytes 15:55:00]File: CITATION [ 29% 23469 bytes 15:55:00] Processing AnIndex (34.19kB) File: CITATION [ 33% 23469 bytes 15:55:00]File: CITATION [ 33% 58484 bytes 15:55:00] Processing base.rdb (2223.37kB) File: CITATION [ 38% 58484 bytes 15:55:00]File: CITATION [ 38% 2335211 bytes 15:55:00] Processing base.rdx (8.94kB) File: CITATION [ 42% 2335211 bytes 15:55:00]File: CITATION [ 42% 2344368 bytes 15:55:00] Processing paths.rds (3.03kB) File: paths.rds [ 46% 2344368 bytes 15:55:00]File: paths.rds [ 46% 2347467 bytes 15:55:00] Processing 00Index.html (147.42kB) File: paths.rds [ 50% 2347467 bytes 15:55:00]File: paths.rds [ 50% 2498429 bytes 15:55:00] Processing R.css (1.69kB) File: paths.rds [ 54% 2498429 bytes 15:55:00]File: paths.rds [ 54% 2500164 bytes 15:55:00] Processing INDEX (23.82kB) File: paths.rds [ 58% 2500164 bytes 15:55:00]File: paths.rds [ 58% 2524556 bytes 15:55:00] Processing demo.rds (0.26kB) File: paths.rds [ 62% 2524556 bytes 15:55:00]File: paths.rds [ 62% 2524823 bytes 15:55:00] Processing features.rds (0.12kB) File: paths.rds [ 67% 2524823 bytes 15:55:00]File: paths.rds [ 67% 2524945 bytes 15:55:00] Processing hsearch.rds (22.39kB) File: paths.rds [ 71% 2524945 bytes 15:55:00]File: paths.rds [ 71% 2547874 bytes 15:55:00] Processing links.rds (13.03kB) File: paths.rds [ 75% 2547874 bytes 15:55:00]File: paths.rds [ 75% 2561216 bytes 15:55:01] Processing package.rds (0.54kB) File: paths.rds [ 79% 2561216 bytes 15:55:01]File: paths.rds [ 79% 2561772 bytes 15:55:01] Processing Rd.rds (21.70kB) File: paths.rds [ 83% 2561772 bytes 15:55:01]File: paths.rds [ 83% 2583995 bytes 15:55:01] Processing base (5.03kB) File: base [ 88% 2583995 bytes 15:55:01]File: base [ 88% 2589147 bytes 15:55:01] Processing base.rdb (1049.85kB) File: base [ 92% 2589147 bytes 15:55:01]File: base [ 92% 3664195 bytes 15:55:01] Processing base.rdx (13.48kB) File: base [ 96% 3664195 bytes 15:55:01]File: base [ 96% 3678003 bytes 15:55:01] Processing Rprofile (7.11kB) File: Rprofile [100% 3678003 bytes 15:55:01]File: Rprofile [100% 3685284 bytes 15:55:01]
setLabel(sb, "file", "<done>") update(sb)
File: <done> [100% 3685284 bytes 15:55:01]
cat("\n")