title: How to handle pipes producing empty data further down the dplyr pipeline
body: <p>This issue occurs in <code>dplyr</code> version 0.30.</p>
  
  <p>I have a chain of pipes <code>%&gt;%</code> starting with a <code>filter</code>. Sometimes this filter reduces the data frame to no rows. Some where further down the pipe line, I have a function which uses <code>if</code> to mutate the data frame. However, this function errors if the data frame has been reduced to zero rows prior.</p>
  
  <p>For example</p>
  
  <pre><code>data(mtcars)
  
  stupid_function &lt;- function(x){
      if( x == 6){
          return(2*x)
      } else {
          return(x)
      }
  }
  
  for(i in 6:10) {
  
      data &lt;-
          mtcars %&gt;% 
          filter(cyl == i) %&gt;%
          rowwise() %&gt;%
          mutate(carb2 = stupid_function(carb)) %&gt;%
          group_by(carb2) %&gt;%
          summarise(mean(wt))
  
      print(data)
  
  }
  </code></pre>
  
  <p>works for <code>i = 6</code> but fails for <code>i = 7</code>, e.g. </p>
  
  <p>Is there anyway to handle this problem? Two approaches I have considered is breaking up the chain in the middle to check that the data has more than one row after filtering, or wrapping everything in a <code>tryCatch</code>.</p>