title: Drop the iteration with warning in a loop
body: <p>In R, I need to fulfill a set in a loop, but sometimes the calculation will generate warnings, I want to get rid of any result with warning, so the final result will without any element with warnings. For example:</p>
  
  <pre><code>result &lt;- numeric(10)
  for (i in 1:length(result)){
   element &lt;- sample(-1:1,1)
   result[i] &lt;- log(element)
  }
  </code></pre>
  
  <p>You can see when <code>element=-1</code>, <code>log(element)=NaN</code>,<code>NaN</code> will still store to <code>result</code> while R will give a warning. I just want to avoid such<code>NaN</code>stored to <code>result</code> based on warning. This is a an easy situation, we can have other option. But the situation I have to face is much more complex. So I hope I can find a method that if there is warning happened, so we will get rid of the result from calculation with warning.</p>