title: Disregarding simple warnings/errors in tryCatch()
body: <p>I'm a huge fan of <code>tryCatch()</code>. However, until today I never really paid attention to the distinction between simple and regular warnings/errors and thus I don't really know how to handle them.</p>
  
  <h2>Actual question</h2>
  
  <p>What I'd like to know is how to tell <code>tryCatch</code> (<a href="http://stat.ethz.ch/R-manual/R-patched/library/base/html/conditions.html" rel="noreferrer">see help file</a>) that simple warnings are OK and that it should return the result of <code>expr</code> instead of jumping to the <code>warning</code> section.</p>
  
  <p>Below you'll find a reproducible example</p>
  
  <hr>
  
  <h2>No <code>tryCatch</code> >> no warning</h2>
  
  <pre><code>require("forecast")
  y   &lt;- ts(c(6178, 7084, 8162, 8462, 9644, 10466, 10748, 9963, 8194, 6848, 7027, 7269, 6775, 7819, 8371, 9069, 10248, 11030, 10882, 10333, 9109, 7685, 7602, 8350, 7829, 8829, 9948, 10638, 11253, 11424, 11391, 10665, 9396, 7775, 7933, 8186, 7444, 8484, 9864, 10252, 12282, 11637, 11577, 12417, 9637, 8094, 9280, 8334, 7899, 9994, 10078, 10801, 12950, 12222, 12246, 13281, 10366, 8730, 9614, 8639, 8772, 10894, 10455, 11179, 10588, 10794, 12770, 13812, 10857, 9290, 10925, 9491, 8919, 11607, 8852, 12537, 14759, 13667, 13731, 15110, 12185, 10645, 12161, 10840, 10436, 13589, 13402, 13103, 14933, 14147, 14057, 16234, 12389, 11595, 12772))
  out &lt;- forecast::auto.arima(x=y)
  &gt; out
  Series: y 
  ARIMA(4,1,1)                    
  
  Coefficients:
           ar1      ar2     ar3      ar4      ma1
        0.6768  -0.2142  0.5025  -0.7125  -0.8277
  s.e.  0.0749   0.0889  0.0874   0.0735   0.0485
  
  sigma^2 estimated as 915556:  log likelihood=-780.33
  AIC=1572.65   AICc=1573.62   BIC=1587.91
  </code></pre>
  
  <h2><code>tryCatch</code> >> simple warning</h2>
  
  <p>When I wrap it with <code>tryCatch</code>, it detects a simple warning that will cause my <code>expr</code> block to be "skipped" in favor of the <code>warning</code> section. Thus the function does not return the estimation result, but the simple warning.</p>
  
  <pre><code>mod &lt;- tryCatch(
      out &lt;- forecast::auto.arima(x=y),
      error=function(e) {
          print(e)
      },
      warning=function(w) {
          print(w)
      }
  )
  
  &gt; mod 
  &lt;simpleWarning in kpss.test(x): p-value smaller than printed p-value&gt;
  </code></pre>
  
  <h2>Current workaround</h2>
  
  <pre><code>if (any(class(mod) == "simpleWarning")) {
      mod &lt;- forecast::auto.arima(x=y)
  }
  
  &gt; mod
  Series: y 
  ARIMA(4,1,1)                    
  
  Coefficients:
           ar1      ar2     ar3      ar4      ma1
        0.6768  -0.2142  0.5025  -0.7125  -0.8277
  s.e.  0.0749   0.0889  0.0874   0.0735   0.0485
  
  sigma^2 estimated as 915556:  log likelihood=-780.33
  AIC=1572.65   AICc=1573.62   BIC=1587.91
  </code></pre>