r 循环和函数的进度条[R]

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了r 循环和函数的进度条[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)
 
}

以上是关于r 循环和函数的进度条[R]的主要内容,如果未能解决你的问题,请参考以下文章

R语言 进度条

R:for循环中的文本进度条

在R闪亮中将fileinput进度条颜色更改为渐变

进度条打印函数

R语言中apply函数

Linux下的简易进度条的实现