添加进度条以复制R中的功能 [英] Adding progress bar to replicate function in R

查看:114
本文介绍了添加进度条以复制R中的功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用replicate多次运行自己的analyse函数(analyse返回列表):

I am using replicate to run my own analyse function multiple times (analyse returns a list):

results <- replicate(reps, analyse())

是否可以添加进度条,以显示当前完成的复制百分比?我已经尝试过txtProgressBar,但是不知道如何在没有for循环的情况下使它工作.

Is there a way to add progress bar, showing the percentage of replications finished at the moment? I have tried with txtProgressBar, but don't know how to make it work without a for-loop.

replicate:

analyse <- function() {
  out <- list('a' = vector('list', 5), 'b' = vector('list', 5))
}
results <- replicate(3, analyse())

在我的情况下,analyse的输出是带有结果的列表的深层列表.我希望每次填充新的results列时都更新进度条,所以在每次复制之后.

In my case, output of analyse is a deep list of lists with results. I would like the progress bar to update every time a new column of results is filled in, so after each replication.

推荐答案

解决方案是使用pbapply包中的pbreplicate()函数.该软件包还包含apply()lapply()sapply()的相应进度栏功能.

The solution is to use pbreplicate() function from pbapply package. This package also contains respective progress bar functions for apply(), lapply() and sapply().

这篇关于添加进度条以复制R中的功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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