title: R Function to import data set and pipeline create variables based on field name/existence
body: <p>I am creating a function to automate importing several data sets, and am having difficulty with variable value assignment in the pipeline.</p>
  <p><strong>The Task:</strong></p>
  <p>I have 20+ data sets that need to be imported and have the same variables calc'ed and created.  The input data sets contain the same fields, except for one field whose name can be one of three possible values ('varYEAR' where 'YEAR' is a one of three possible years), but whose underlying data is of the same type.  I am attempting to assign the values of this varYEAR vector to a uniformly-named variable 'varXXXX' so that further mutations may reference this latter variable and not have to worry about the original variable name.  The code below has been simplified to focus on the crux of the issue.</p>
  <p><strong>Current Example Code/Output:</strong></p>
  <pre><code>set_import &lt;- function(input_path,year) {
     temp_set &lt;- read_table(input_path) %&gt;%
       mutate(MSAXXXX = ifelse(exists('var2003'),var2003,var2013))
  }
  
  View(temp_set)
  
         var2003        varXXXX
   1     41929          41929
   2     33820          41929
   3     27642          41929
   4     88111          41929
  </code></pre>
  <p>I have tried a few different approaches to this, including:
  <code>mutate(varXXXX = ifelse('var2003' %in% names(.),var2003,var2013))</code> as well as trying it outside of the pipeline with <code>temp_set$MSAXXXX = as.character(ifelse('var2003' %in% names(temp_set),temp_set$var2003,var2013))</code>.  Each has resulted in the same output set above.</p>
  <p><strong>Desired Output:</strong></p>
  <pre><code>View(temp_set)
  
         var2003        varXXXX
   1     41929          41929
   2     33820          33820          
   3     27642          27642          
   4     88111          88111          
  </code></pre>
  <p>The best I can surmise right now is that the 'if' statement is predicated on a single check, and for some reason it populates the varXXXX field with the first value it finds in said check.  I'm at a loss, and would really appreciate some help!  Thanks in advance.</p>