create_pb {SPB}R Documentation

Function to create a simple progress bar

Description

Function to create a simple progress bar

Usage

create_pb(
  length,
  remaining = "-",
  done = "=",
  percentage = TRUE,
  message = TRUE,
  custom.message = NULL,
  trim = 6L,
  print = TRUE,
  colour = "red",
  bg.colour = "white"
)

Arguments

length

Length of the progress bar. For instance, in a loop it would be the number of iterations to complete.

remaining

The character (string of unitary length) used to represent operations still to do.

done

The character (string of unitary length) used to represent operations already completed

percentage

Logical | Whether to print the percentage progess after the bar. Defaults to TRUE

message

Logical | Whether to print a message before the progress bar. Defaults to TRUE

custom.message

Optional message to be printed before the progress bar. Defaults to NULL, which prints simply 'Progress status:',

trim

How many points to trim from the maximum length of the terminal output. Default to 6L

print

Logical | Whether to print the progress bar after its initialisation. Defaults to TRUE

colour

Styling of the progress bar object. It can be a single string, in which case it applies to all the part of the progress bar (message, bar and percentage). It can also be a vector of length 3, in which case each string applies to one of the items (respectively message, bar and percentage). The strings must be taken amongst the following values:

  • black;

  • blue;

  • cyan;

  • green;

  • magenta;

  • red;

  • white;

  • yellow.

bg.colour

Styling of the progress bar object's background. It can be a single string, in which case it applies to all the part of the progress bar (message, bar and percentage). It can also be a vector of length 3, in which case each string applies to one of the items (respectively message, bar and percentage). The strings must be taken amongst the following values:

  • Black;

  • Blue;

  • Cyan;

  • Green;

  • Magenta;

  • Red;

  • White;

  • Grey;

  • Yellow.

Value

An object of the S4 class simple.progess.bar containing:

message

A string representing the message to be printed together with the bar

bar

The progress bar

percentage

Progress in percentage

length

Length of the progress bar (integer)

remaining

Character representing the remaining operations

done

Character representing the operations already completed

style_msg

Styling of message using crayon

style_bar

Styling of bar using crayon

style_perc

Styling of percentage using crayon

Author(s)

Telarico, Fabio Ashtar

Examples


# Example without custom colours or custom message
pb<-create_pb(length=10, print=TRUE)

# Example without custom colours but with custom message
pb<-create_pb(length=10, custom.message = 'Custom progress message:',
print = TRUE)

# Example with custom colours and custom message
pb<-create_pb(length=10, custom.message = 'Custom progress message:',
print = TRUE,colour = c('magenta','red','blue'))


[Package SPB version 1.0 Index]