R: show error and warning messages in foreach %dopar%
<p>I'm new to using foreach() %dopar% for paralleling, and I have some problems about how it handles errors or warnings.</p>

<ol>
<li><p>when I use try() with my customized error message within foreach() %dopar%, the "native" error message doesn't show up:</p>

<pre><code>test &lt;- function(x) {
  if (x==2) "a"/2
}

foreach(i=1:3) %dopar% {
  tryout &lt;- try(test(i))
  if (class(tryout)=="try-error") print("Error!")
}
</code></pre>

<p>In this case the "native" error message: <code>Error in "a"/2 : non-numeric argument to binary operator</code> doesn't show up, and only the <code>Error!</code> from try() error catching will be printed. However both error messages will be printed when not using foreach() %dopar%. So how to make both error messages show up?</p></li>
<li><p>In the above case, when there are warnings, whether additional to errors or not, the warning messages are not printed, for example with the same foreach() block as above and the <code>test()</code> below:</p>

<pre><code>test &lt;- function(x) {
  if (x==2) warning("Warning!")
}
</code></pre>

<p>So how to show the warnings?</p></li>
</ol>

<p>p.s. I found that if I simply use try(test(i)) within %dopar% then the "native" error messages and the warnings will be printed, but I do want to include my own error message in real-life situations. I also tried using <code>tryCatch()</code> instead of <code>try()</code>, but it didn't solve the problem.</p>

<p>Thanks!</p>