ProgressBarText-class          package:affy          R Documentation

_C_l_a_s_s "_P_r_o_g_r_e_s_s_B_a_r_T_e_x_t"

_D_e_s_c_r_i_p_t_i_o_n:

     A class to handle progress bars in text mode

_O_b_j_e_c_t_s _f_r_o_m _t_h_e _C_l_a_s_s:

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

_S_l_o_t_s:


     '_s_t_e_p_s': Object of class '"integer"'. The total number of steps
          the progress bar should represent

     '_b_a_r_s_t_e_p_s': Object of class '"integer"'. The size of the progress
          bar.

     '_i_n_t_e_r_n_a_l_s': Object of class '"environment"'. For internal use.

_M_e_t_h_o_d_s:


     _c_l_o_s_e '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.

     _i_n_i_t_i_a_l_i_z_e 'signature(.Object = "ProgressBarText")': initialize a
          instance.

     _o_p_e_n '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).

     _u_p_d_a_t_e 'signature(object = "ProgressBarText")': Update the
          progress bar (see examples).

_A_u_t_h_o_r(_s):

     Laurent

_E_x_a_m_p_l_e_s:

     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)
         update(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) {
         update(pbt)
       }
       close(pbt)
     }

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

