添加进度条以复制R中的功能 [英] Adding progress bar to replicate function in 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屋!