title: Passing column name into function
body: <p>I have a simple problem with non-standard evaluation: passing a variable name as an argument into a function.</p>
  <p>As a reproducible example, here's a simple thing: taking the mean of one variable, <code>mpg</code> from the <code>mtcars</code> dataset. My end goal is to have a function where I can input the dataset and the variable, and get the mean.</p>
  <p>So without a function:</p>
  <pre class="lang-r prettyprint-override"><code>library(tidyverse)
  mtcars %&gt;% summarise(mean = mean(mpg))
  
  #&gt;       mean
  #&gt; 1 20.09062
  </code></pre>
  <p>I've tried to use <code>get()</code> for non-standard evaluation, but I'm getting errors:</p>
  <pre class="lang-r prettyprint-override"><code>library(tidyverse)
  summary_stats &lt;- function(variable, dataframe){
    dataframe %&gt;% summarise(mean = get(variable))
  }
  
  summary_stats(mpg, mtcars)
  
  #&gt; Error: Problem with `summarise()` input `mean`.
  #&gt; x invalid first argument
  #&gt; ℹ Input `mean` is `get(variable)`.
  </code></pre>
  <p><sup>Created on 2020-09-19 by the <a href="https://reprex.tidyverse.org" rel="nofollow noreferrer">reprex package</a> (v0.3.0)</sup></p>
  <h2>Edit:</h2>
  <p>I also had one additional follow-up question.</p>
  <p>I also need the <code>variable</code> argument as a <code>char</code> string, I tried the code below, but I'm still missing how to do that:</p>
  <pre class="lang-r prettyprint-override"><code>library(tidyverse)
  summary_stats &lt;- function(variable, dataframe){
    dataframe %&gt;% summarise(mean = mean({{variable}}))
    print(as.character({{variable}}))
  }
  
  summary_stats(disp, mtcars)
  #&gt; Error in print(as.character({: object 'disp' not found
  </code></pre>
  <p><sup>Created on 2020-09-19 by the <a href="https://reprex.tidyverse.org" rel="nofollow noreferrer">reprex package</a> (v0.3.0)</sup></p>