title: How to pass column names into a function dplyr
body: <p>I'm trying to create a simple summary function to speed up the reporting of multiple columns of data for use in a R Markdown file.</p>
  
  <p>var1 is a categorical column of data, t_var is an integer representing the quarter of data, and dt is the full data.</p>
  
  <pre><code>summarise_data_categorical &lt;- function(var1, t_var, dt){
  
    print(var1)
    print(t_var)
  
    #Select the columns to aggregate
    group_func &lt;- dt %&gt;% 
      select(one_of(t_var, var1)) %&gt;%
      group_by(t_var,var1)
  
    #create simple count summary
    count_table &lt;- group_func %&gt;%
      summarise(count = n()) %&gt;%
      spread(t_var, count)
  
    #create a frequency version of the same table...
    freq &lt;- dt %&gt;%
      select(t_var, var1) %&gt;%
      group_by(t_var,var1) %&gt;%
      summarise(count = n()) %&gt;%
      mutate(freq = round(count / sum(count),3)*100) %&gt;%
      select(-count)
  
    #Present that table
    freq_table &lt;- freq %&gt;%
      spread(t_var, freq)
  
    #Create the chart to do the same thing..
    freq_chart &lt;- freq %&gt;%
      ggplot()+
      geom_line(mapping=aes(x=t_var, y = freq, colour=var1))
  
    #Compile outputs as a list
    results &lt;- list(count_table, freq_table, freq_chart)
  
    #Return list
    results
  
  }
  </code></pre>
  
  <p>Say I've got a frame:</p>
  
  <pre><code>fr &lt;- data.frame(lets = sample(LETTERS, 100, replace=TRUE),
             `quarter type` = sample(1:4, 100, replace=TRUE))
  </code></pre>
  
  <p>If I run the function, thus:</p>
  
  <pre><code>summarise_data_categorical("lets", "quarter type", fr)
  </code></pre>
  
  <p>The initial output is promising: </p>
  
  <pre><code>[1] "lets"
  [1] "quarter type"
  </code></pre>
  
  <p>(NOTE: in trying to recreate the data, for some reason I also receive the warning: </p>
  
  <p>Unknown variables: <code>quarter type</code>, 
  Although this doesn't appear in my original data)</p>
  
  <p>The main thing is I get an error:</p>
  
  <pre><code>Error in resolve_vars(new_groups, tbl_vars(.data)) : unknown variable to group by : t_var
  </code></pre>
  
  <p>Having come from Python, I'm still a bit confused on how to refer to columns. Can someone explain how I can fix what I've got wrong?</p>