jorgeassis
10/31/2018 - 9:34 AM

Progress Bar for Loops and Functions [R]

Progress Bar for Loops and Functions [R]


## --------------------------------------------------
## --------------------------------------------------
##
## Progress Bar for Loops and Functions
## Muffins 'n' Code
## https://github.com/jorgeassis
##
## --------------------------------------------------
## --------------------------------------------------

iteractions <- 1000

for ( simulation.step in 1:iteractions ) {
  
  ## --------------------------------------------------------
  
  ## Progress
  
  time.i <- Sys.time()
  if(simulation.step == 1) { time.f <- time.i}
  progress.percent <- round((simulation.step / iteractions) * 100)
  time.take.step.min <- round(as.numeric(difftime(time.i, time.f, units = "mins")))
  
  cat('\014')
  cat('\n')
  cat('\n Running step #',simulation.step,'| Time taken',time.take.step.min,'mins.')
  cat('\n')
  
  cat('\n',paste0(rep("-",100),collapse = ""))
  cat('\n',paste0(rep("-",progress.percent),collapse = ""),"||",progress.percent,"%")
  cat('\n',paste0(rep("-",100),collapse = ""))

  # Code here
  # Sys.sleep(0.01)
 
}