r - R 中具有复杂函数和 plyr 的 tryCatch

标签 r error-handling parallel-processing try-catch domc

我有一个复杂的长函数,我用它来进行模拟。它可能会产生错误,主要与最终具有零方差的相等值的随机向量有关,被输入到 PCA 或逻辑回归中。

我正在使用 doMCplyr 在集群上执行它。我不想tryCatch函数内部的每一个小事情,因为错误的可能性很多,而且每个错误的概率都很小。

如何 tryCatch 每次运行,而不是 tryCatch 处理每一行?代码是这样的:

iteration = function(){
    a really long simulation function where errors can happen
    }
reps = 10000
results = llply(1:reps, function(idx){out<-iteration()},.parallel=TRUE)

大约一年后编辑: foreach 包使这比使用 plyr

更容易
library(foreach)
output <- foreach(i=1:reps, .errorhandling = 'remove')%dopar%{
  function
}

最佳答案

您可以将 try catch 循环包装在传递给 llply 的函数中吗?

results = llply(1:reps, function(idx){
    out = NA
    try({ 
        out<-iteration()
    }, silent=T)
    out
},.parallel=TRUE)

关于r - R 中具有复杂函数和 plyr 的 tryCatch,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15075113/

相关文章:

r - 如何对表示为字符串的值和运算符执行算术运算?

R - 如何将文件从一个位置复制并粘贴到 s3 存储桶中的另一个位置(使用 aws.s3)?

c++ - 链接器命令失败,退出代码为1(错误;似乎无法修复)

r - ggplot 科学轴标签 - 按 1e6 缩放值并格式 "E-06"

r - 将整数顺序分配给十进制数

linux - "Fatal: there are problems with fetch_image.cgi"使用 LabelMeAnnotationTool

bash - bash脚本,将stderr定向到文件,将stdout + stderr定向到终端,并返回退出代码

performance - 理解阿姆达尔定律

c# - Azure - C# 并发 - 最佳实践

bash - Bash 中的并行 wget