title: Using filter() with across() to keep all rows of a data frame that include a missing value for any variable
body: <p>Sometimes I want to view all rows in a data frame that will be dropped if I drop all rows that have a missing value for any variable. In this case, I'm specifically interested in how to do this with <code>dplyr</code> 1.0's <code>across()</code> function used inside of the <code>filter()</code> verb. </p>
  
  <p>Here is an example data frame:</p>
  
  <pre><code>df &lt;- tribble(
    ~id, ~x, ~y,
    1, 1, 0,
    2, 1, 1,
    3, NA, 1,
    4, 0, 0,
    5, 1, NA
  )
  </code></pre>
  
  <p>Code for keeping rows that <em>DO NOT</em> include any missing values is provided on the <a href="https://dplyr.tidyverse.org/articles/colwise.html" rel="noreferrer">tidyverse website</a>. Specifically, I can use:</p>
  
  <pre><code>df %&gt;% 
    filter(
      across(
        .cols = everything(),
        .fns = ~ !is.na(.x)
      )
    )
  </code></pre>
  
  <p>Which returns:</p>
  
  <pre><code># A tibble: 3 x 3
       id     x     y
    &lt;dbl&gt; &lt;dbl&gt; &lt;dbl&gt;
  1     1     1     0
  2     2     1     1
  3     4     0     0
  </code></pre>
  
  <p>However, I can't figure out how to return the opposite -- rows <em>with</em> a missing value in any variable. The result I'm looking for is:</p>
  
  <pre><code># A tibble: 2 x 3
       id     x     y
    &lt;dbl&gt; &lt;dbl&gt; &lt;dbl&gt;
  1     3    NA     1
  2     5     1    NA
  </code></pre>
  
  <p>My first thought was just to remove the <code>!</code>:</p>
  
  <pre><code>df %&gt;% 
    filter(
      across(
        .cols = everything(),
        .fns = ~ is.na(.x)
      )
    )
  </code></pre>
  
  <p>But, that returns zero rows.</p>
  
  <p>Of course, I can get the answer I want with this code if I know all variables that have a missing value ahead of time:</p>
  
  <pre><code>df %&gt;% 
    filter(is.na(x) | is.na(y))
  </code></pre>
  
  <p>But, I'm looking for a solution that doesn't require me to know which variables have a missing value ahead of time. Additionally, I'm aware of how to do this with the <code>filter_all()</code> function: </p>
  
  <pre><code>df %&gt;% 
    filter_all(any_vars(is.na(.)))
  </code></pre>
  
  <p>But, the <code>filter_all()</code> function has been superseded by the use of <code>across()</code> in an existing verb. See <a href="https://dplyr.tidyverse.org/articles/colwise.html" rel="noreferrer">https://dplyr.tidyverse.org/articles/colwise.html</a></p>
  
  <p>Other unsuccessful attempts I've made are:</p>
  
  <pre><code>df %&gt;% 
    filter(
      across(
        .cols = everything(),
        .fns = ~any_vars(is.na(.x))
      )
    )
  
  df %&gt;% 
    filter(
      across(
        .cols = everything(),
        .fns = ~!!any_vars(is.na(.x))
      )
    )
  
  df %&gt;% 
    filter(
      across(
        .cols = everything(),
        .fns = ~!!any_vars(is.na(.))
      )
    )
  
  df %&gt;% 
    filter(
      across(
        .cols = everything(),
        .fns = ~any(is.na(.x))
      )
    )
  
  df %&gt;% 
    filter(
      across(
        .cols = everything(),
        .fns = ~any(is.na(.))
      )
    )
  </code></pre>