I am trying to use tryCatch() in a linux version of R following a recommendation to a previous post (see Linux Server crash in R parallel - Error in unserialize(node$con) : error reading from connection). Basically my code is in the following structure:
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
This code is ran in parallel at continues to try different input parameters in the function Calibrate and DEoptim tries to find the best set of input parameters to maximise Nashsutcliffe (the objective function). Although the code runs fine from anywhere between a couple of minutes to a couple of hours, eventually it fails showing:
Error in unserialize(node$con) : error reading from connection
So how would I incorporate tryCatch() into the code above to catch the error. I have looked at the documentation but don't understand how to use it. Any help would be appreciated (suggested by Roman Luštrik)?
Many thanks
Antony Walker