我正在尝试在推荐前一篇文章后在Linux版本的R中使用tryCatch()(参见Linux Server crash in R parallel - Error in unserialize(node$con) : error reading from connection)。基本上我的代码采用以下结构:
Load libraries
Set some input parameters
ans <- DEoptim(Calibrate,lower,upper,DEoptim.control(trace=TRUE,parallelType=1,parVar=c(parVarnames),packages=c("raster","rgdal","maptools","Cairo")))
Calibrate is a function that calls lots of other functions
At the end it returns a variable (-Nashsutcliffe) to DEoptim
此代码并行运行,继续在函数Calibrate中尝试不同的输入参数,并且DEoptim尝试找到最佳的输入参数集以最大化Nashsutcliffe(目标函数)。虽然代码可以在几分钟到几个小时之间的任何地方运行良好,但最终却无法显示:
Error in unserialize(node$con) : error reading from connection
那么如何将tryCatch()合并到上面的代码中以捕获错误。我查看了文档,但不明白如何使用它。任何帮助将不胜感激(RomanLuštrik建议)?
非常感谢
Antony Walker