ProgressBarText-class: Class "ProgressBarText"

Description Objects from the Class Slots Methods Author(s) Examples

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

 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
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))

affy documentation built on Nov. 8, 2020, 8:18 p.m.