Last data update: 2014.03.03

R: Class "ProgressBarText"
ProgressBarText-classR Documentation

Class "ProgressBarText"

Description

A class to handle progress bars in text mode.

Objects from the Class

Objects can be created by calls of the form new("ProgressBarText", steps).

Slots

steps:

Object of class "integer". The total number of steps the progress bar should represent.

barsteps:

Object of class "integer". The size of the progress bar.

internals:

Object of class "environment". For internal use.

Methods

close

signature(con = "ProgressBarText"): Terminate the progress bar (i.e. print what needs to be printed). Note that closing the instance will ensure the progress bar is plotted to its end.

initialize

signature(.Object = "ProgressBarText"): initialize a instance.

open

signature(con = "ProgressBarText"): Open a progress bar (i.e. print things). In the case open is called on a progress bar that was 'progress', the progress bar is resumed (this might be useful when one wishes to insert text output while there is a progress bar running).

updateMe

signature(object = "ProgressBarText"): Update the progress bar (see examples).

Author(s)

Laurent

Examples

f <- function(x, header = TRUE) {
  pbt <- new("ProgressBarText", length(x), barsteps = as.integer(20))

  open(pbt, header = header)

  for (i in x) {
    Sys.sleep(i)
    updateMe(pbt)
  }
  close(pbt)
}

## if too fast on your machine, change the number
x <- runif(15)

f(x)
f(x, header = FALSE)

## 'cost' of the progress bar:
g <- function(x) {
  z <- 1
  for (i in 1:x) {
    z <- z + 1
  }
}
h <- function(x) {
  pbt <- new("ProgressBarText", as.integer(x), barsteps = as.integer(20))
  open(pbt)
  for (i in 1:x) {
    updateMe(pbt)
  }
  close(pbt)
}

system.time(g(10000))
system.time(h(10000))

Results


R version 3.3.1 (2016-06-21) -- "Bug in Your Hair"
Copyright (C) 2016 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> library(affy)
Loading required package: BiocGenerics
Loading required package: parallel

Attaching package: 'BiocGenerics'

The following objects are masked from 'package:parallel':

    clusterApply, clusterApplyLB, clusterCall, clusterEvalQ,
    clusterExport, clusterMap, parApply, parCapply, parLapply,
    parLapplyLB, parRapply, parSapply, parSapplyLB

The following objects are masked from 'package:stats':

    IQR, mad, xtabs

The following objects are masked from 'package:base':

    Filter, Find, Map, Position, Reduce, anyDuplicated, append,
    as.data.frame, cbind, colnames, do.call, duplicated, eval, evalq,
    get, grep, grepl, intersect, is.unsorted, lapply, lengths, mapply,
    match, mget, order, paste, pmax, pmax.int, pmin, pmin.int, rank,
    rbind, rownames, sapply, setdiff, sort, table, tapply, union,
    unique, unsplit

Loading required package: Biobase
Welcome to Bioconductor

    Vignettes contain introductory material; view with
    'browseVignettes()'. To cite Bioconductor, see
    'citation("Biobase")', and for packages 'citation("pkgname")'.

> png(filename="/home/ddbj/snapshot/RGM3/R_BC/result/affy/ProgressBarText-class.Rd_%03d_medium.png", width=480, height=480)
> ### Name: ProgressBarText-class
> ### Title: Class "ProgressBarText"
> ### Aliases: ProgressBarText-class close,ProgressBarText-method
> ###   initialize,ProgressBarText-method open,ProgressBarText-method
> ###   updateMe updateMe,ProgressBarText-method
> ### Keywords: classes
> 
> ### ** Examples
> 
> f <- function(x, header = TRUE) {
+   pbt <- new("ProgressBarText", length(x), barsteps = as.integer(20))
+ 
+   open(pbt, header = header)
+ 
+   for (i in x) {
+     Sys.sleep(i)
+     updateMe(pbt)
+   }
+   close(pbt)
+ }
> 
> ## if too fast on your machine, change the number
> x <- runif(15)
> 
> f(x)
|                    |
|####################|
> f(x, header = FALSE)
|####################|
> 
> ## 'cost' of the progress bar:
> g <- function(x) {
+   z <- 1
+   for (i in 1:x) {
+     z <- z + 1
+   }
+ }
> h <- function(x) {
+   pbt <- new("ProgressBarText", as.integer(x), barsteps = as.integer(20))
+   open(pbt)
+   for (i in 1:x) {
+     updateMe(pbt)
+   }
+   close(pbt)
+ }
> 
> system.time(g(10000))
   user  system elapsed 
  0.004   0.000   0.002 
> system.time(h(10000))
|                    |
|####################|
   user  system elapsed 
  0.156   0.008   0.163 
> 
> 
> 
> 
> 
> 
> dev.off()
null device 
          1 
>