title: Filter try-error objects from a column / list (dplyr but also more general)
body: <p>I was playing with some data that I gathered in a data frame, where I want to apply a function to all the elements of a column. Usually I use <code>purrr::map()</code> for this. However, sometimes this will not work if the functions returns an error for one of the elements of a column:</p>
  
  <pre><code>f &lt;- function(x) {
    if(x==2) stop("I hate 2") else x
  }
  
  library(dplyr)
  dd &lt;- data.frame(x = c(1:2))
  dd2 &lt;- dd %&gt;% 
    mutate(fx = purrr::map(.x = x, .f = ~f(.)))
  Error: I hate 2
  </code></pre>
  
  <p>So I can wrap my function <code>f</code> with <code>try()</code>, and obtain a column of results:</p>
  
  <pre><code>&gt; dd2 &lt;- dd %&gt;% 
  +   mutate(fx = purrr::map(.x = x, .f = ~try(f(.))))
  Error in f(.) : I hate 2
  &gt; dd2
    x                         fx
  1 1                          1
  2 2 Error in f(.) : I hate 2\n
  </code></pre>
  
  <p>Now I would ideally like to use <code>filter()</code> to filter out the line(s) with the  errors, but I can't seem to be able to do that. Neither of these will yield a data frame with just the first line here:</p>
  
  <pre><code>dd2 %&gt;% filter(is.integer(fx) )
  dd2 %&gt;% filter(is.integer(.$fx) )
  
  dd2 %&gt;% filter(class(fx) != "try-error")
  dd2 %&gt;% filter(class(.$fx) != "try-error")
  
  lapply(dd2, is.numeric)
  </code></pre>
  
  <p>A dirty trick that I was thinking about would be to use <code>try_catch()</code> instead, and make it return an object of the same type as <code>f()</code> in case of error, for example <code>-99999</code> here, and filter those out, but I am looking for a cleaner solution. </p>