如何收到有关循环/应用程序正在进行的进度的警报 [英] How to be alerted about the ongoing progress of a loop/lapply

查看:81
本文介绍了如何收到有关循环/应用程序正在进行的进度的警报的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

R中,有时我想知道一个长的for looplapply正在进行的进度.

In R, I will sometimes have a long for loop or lapply that I want to know the ongoing progress of.

以下内容符合我想要的但不起作用:

Something like the following is in the spirit of what I want but doesn't work:

lapply(1:n,function(i) { print(i); MAIN COMPUTATIONS })

理想情况下,上面的代码会在lapply的每次新迭代开始时打印i.

Ideally the above would print i at the beginning of each new iteration of the lapply.

问题::我如何获得正在进行的进度更新,以更新我的lapplyfor loop完成了多少次迭代?

QUESTION: How do I get ongoing progress updates of how many iterations my lapply or for loop has done?

推荐答案

听起来好像您在Windows上使用RGui.菜单之一中应该有一个选项,告诉它不要缓冲输出.或者,您可以在每次打印后致电flush.console.

It sounds like you're using RGui on Windows. There should be an option in one of the menus to tell it to not buffer the output. Alternatively you could call flush.console after every time you print.

lapply(1:1000, function(i){print(i); flush.console()})

请注意,这会使代码变慢一点.

Note that this will slow down the code a little bit.

这篇关于如何收到有关循环/应用程序正在进行的进度的警报的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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