从Lapply()获得临时结果
我有一些lapply代码,需要很长时间才能计算。类似的事情:
n <- 10^7
res <- lapply(1:n, function(i){
print(round(i/n*100, 0))
rnorm(100)
})
我们可以以某种方式保存临时结果,而回合(i/n*100,0)
比100%少,即代码仍在运行?
我现在正在运行实际的lapply()
代码,零件print(rough(i/n*100,0))
告诉我,我的计算机几乎完成了(99%!)。问题是我需要关闭计算机,因为我离开了工作场所。在res&lt; - lapply(...)
零件仍在运行时,是否有机会获得数据R的计算?真的不想让他明天再次计算这99%的年龄。
I have some lapply code which takes a really long while to compute. Something like this:
n <- 10^7
res <- lapply(1:n, function(i){
print(round(i/n*100, 0))
rnorm(100)
})
Can we somehow save the interim results while round(i/n*100, 0)
is less then 100%, i.e. the code is still running?
I am running the my actual lapply()
code right now and the part print(round(i/n*100, 0))
tells me that my computer is almost done (99%!). The problem is that I need to turn off the computer because I leave my work place. Is there any chance to get the data R has calculated so far while the res <- lapply(...)
part is still running? Really don`t want him to calculate for ages those 99% tomorrow again..
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
一旦
lapply()
代码运行,似乎无法捕获临时结果。但是,有两个选项@gregorthomas建议
&lt;&lt; -
在lapply(Lapply()
函数中,确实保存了临时结果。这是问题中代码的第二个选项:
现在我们可以查看并查看临时数据实际上保存了:
Once the
lapply()
code runs there seems to be no way to catch the interim results. But there are two optionsfor
loop as suggested by @GregorThomas<<-
inside thelapply()
function which does save interim results.Here is the second option for the piece of code in the question:
Now we can have a look and see that the interim data is actually saved: