title: Using tryCatch in R
body: <p>Using e1071, one can tune the parameters of SVM models</p>
  
  <pre><code>svmmodels &lt;- lapply(trainingtemp, function(data)
                      {
                        svm.tune &lt;- tune.svm(label~., data=data,
                                             gamma=10^(-3:0), cost=10^(-3:3));
                        svm(label~., data=data,
                            method="C-classification",
                            kernel="radial", cost=svm.tune$best.parameters$cost, 
                                 gamma=svm.tune$best.parameters$gamma)
                      })
  </code></pre>
  
  <p>But with certain data, an empty model is returned by tune.svm (could be several reasons for that). How one can engage tryCatch in this situation that if tune.svm returns the following error message then one can use the default parameters in svm function.</p>
  
  <pre><code>Error in predict.svm(ret, xhold, decision.values = TRUE) : 
   Model is empty!
  Calls: lapply ... svm.formula -&gt; svm.default -&gt; na.action -&gt; predict -&gt; predict.svm
  Execution halted
  </code></pre>