如何在R中显示代码的进度? [英] How to show the progress of code in R?

查看:45
本文介绍了如何在R中显示代码的进度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我现在正在处理一个大型数据集,某些函数可能需要数小时才能处理.我想知道如何通过进度条或数字(1,2,3,...,100)显示代码的进度.这是一个例子.谢谢.

I am now dealing with a large dataset and some functions may take hours to process. I wonder how I can show the progress of the code through a progress bar or number(1,2,3,...,100). Here is an example. Thanks.

require(Kendall)
mydata=matrix(rnorm(6000*300),ncol = 300)
result=as.data.frame(matrix(nrow = 6000,ncol = 2))
for (i in 1:6000) {
  abc=MannKendall(mydata[i,])
  result[i,1]=abc$tau
  result[i,2]=abc$sl
}

顺便说一下,我找到了链接 https://ryouready.wordpress.com/2009/03/16/r-monitor-function-progress-with-a-progress-bar/ 非常有用.但是,我不知道如何将链接中的代码与我自己的功能结合起来.有人有想法吗?谢谢.这是上面链接中的代码.

By the way, I find the link https://ryouready.wordpress.com/2009/03/16/r-monitor-function-progress-with-a-progress-bar/ very usefull. However, I do not know how to combine the code in the link with my own function. Anyone has an idea? Thanks. Here is the code from the above link.

total <- 20
# create progress bar
pb <- txtProgressBar(min = 0, max = total, style = 3)
for(i in 1:total){
   Sys.sleep(0.1)
   # update progress bar
   setTxtProgressBar(pb, i)
}
close(pb)

推荐答案

这应该有效:

mydata=matrix(rnorm(6000*300),ncol = 300)
result=as.data.frame(matrix(nrow = 6000,ncol = 2))
progression<-winProgressBar(title = "Progress bar", min = 0,max = 6000 , width = 300)
for (i in 1:6000) {
  abc=MannKendall(mydata[i,])
  result[i,1]=abc$tau
  result[i,2]=abc$sl
  setWinProgressBar(progression, i, title=paste(round(progress/6000)*100,"% done"))
}

这篇关于如何在R中显示代码的进度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆