我在这里尝试了这些项目,但不能只是在连续(不是dopar)循环中简单中断foreach:Is there any way to break out of a foreach loop?
我只想要一个简单的停止或中断操作,以在当前迭代(即下面的i = 3)处停止循环并在i = 3处停止循环:
library(foreach)
foreach(i=c(1:10), .errorhandling ='stop')%do%{
print(i)
Sys.sleep(2)
if(i==3){break} #doesn't do anything
if(i==3){stop("stopped")} #doesn't stop the function but kicks an error notice at the end
}