title: Fill a new column from multiple columns if they exist
body: <p>Example data.frame:</p>
  <pre><code>df &lt;- data.frame(col_1=c(&quot;A&quot;, NA, NA), col_2=c(NA, &quot;B&quot;, NA), col_3=c(NA, NA, &quot;C&quot;), other_col=rep(&quot;x&quot;, 3), stringsAsFactors=F)
  df
    col_1 col_2 col_3 other_col
  1     A  &lt;NA&gt;  &lt;NA&gt;         x
  2  &lt;NA&gt;     B  &lt;NA&gt;         x
  3  &lt;NA&gt;  &lt;NA&gt;     C         x
  </code></pre>
  <p>I can create a new column <code>new_col</code> filled with non-NA values from the 3 columns <code>col_1</code>, <code>col_2</code> and <code>col_3</code>:</p>
  <pre><code>df %&gt;% 
  mutate(new_col = case_when(
     !is.na(col_1) ~ col_1,
     !is.na(col_2) ~ col_2,
     !is.na(col_3) ~ col_3,
     TRUE ~ &quot;none&quot;))
  
    col_1 col_2 col_3 other_col new_col
  1     A  &lt;NA&gt;  &lt;NA&gt;         x       A
  2  &lt;NA&gt;     B  &lt;NA&gt;         x       B
  3  &lt;NA&gt;  &lt;NA&gt;     C         x       C
  </code></pre>
  <p>However, sometimes the number of columns from which I pick the <code>new_col</code> value can vary.</p>
  <p>How could I check that the columns exist before applying the previous <code>case_when</code> command?</p>
  <p>The following triggers an error:</p>
  <pre><code>df %&gt;% 
  select(-col_3) %&gt;% 
  mutate(new_col = case_when(
     !is.null(.$col_1) &amp; !is.na(col_1) ~ col_1,
     !is.null(.$col_2) &amp; !is.na(col_2) ~ col_2,
     !is.null(.$col_3) &amp; !is.na(col_3) ~ col_3, 
     TRUE ~ &quot;none&quot;))
  
  Error: Problem with `mutate()` input `new_col`.
     x object 'col_3' not found
     ℹ Input `new_col` is `case_when(...)`.
  </code></pre>