title: How do I use try statements in R?
body: <p>So I'm trying to loop through some data and use them in my code. The place where I need this try thing is at the following:</p>
  
  <pre><code>for (number in numbers) {
      CTV_volume &lt;- CTV[ which(CTV$Key==number), ]$volume
      PTV_volume &lt;- PTV[ which(PTV$Key==number), ]$volume
      ITV_volume &lt;- ITV[ which(ITV$Key==numbers), ]$volume
  
      large_volume &lt;- large_margin_vol_calc(radius_calc(CTV_volume), a_large, b_large)
      small_volume &lt;- small_margin_vol_calc(radius_calc(CTV_volume), a_small, b_small) 
  }
  </code></pre>
  
  <p>The thing is that the <code>CTV_volume</code> calculation in the two last lines (<code>large_volume</code> and <code>small_volume</code>) depends on data from the first line above (<code>CTV_volume</code>). However, for each iteration of the loop there is a chance that there is no CTV for that particular key/number, and instead I need to use another one, i.e. ITV. But first and foremost I need it to use the CTV first if that is present, and if not, then the ITV word.</p>
  
  <p>How is that accomplished in R?</p>