title: Creating dplyr function with passing column argument
body: <p>I am trying to pass column name as argument to a function which uses dplyr functions within. </p>
  
  <p>There were multiple questions already asked around this theme and I tried all of them, everything seems to throw some or the other error. </p>
  
  <p>I used enquo with !! as given <a href="https://stackoverflow.com/questions/47466577/passing-column-names-through-multiple-functions-with-dplyr">here</a>. Tried using !! as_label to combat the error I got from the previous step using <a href="https://stackoverflow.com/questions/55406546/how-to-fix-quosures-can-only-be-unquoted-within-a-quasiquotation-context-error">this</a>. Also tried to use group_by_ instead of group_by as mentioned <a href="https://www.r-bloggers.com/data-frame-columns-as-arguments-to-dplyr-functions/" rel="nofollow noreferrer">here</a>. I have also tried the curly operator for resolution</p>
  
  <pre><code>userMaster &lt;- structure(list(user_id = c(1, 2, 3, 4, 5), city = structure(c(5L, 
  5L, 8L, 9L, 10L), .Label = c("Austin", "Boise", "Boston", "Chicago", 
  "Dallas", "Denver", "Detroit", "Kansas City", "Las Vegas", "Los Angeles", 
  "Manhattan", "Miami", "Minneapolis", "New York City", "Oklahoma City", 
  "Omaha", "Phoenix", "Saint Louis", "San Francisco", "Washington DC"
  ), class = "factor"), source = structure(c(2L, 2L, 2L, 2L, 2L
  ), .Label = c("Adwords", "Organic", "Search Ads"), class = "factor")), row.names = c(NA, 
  5L), class = "data.frame")
  
  userCount &lt;- function(table, metric){
    col_enquo &lt;- enquo(metric)
  
    summary &lt;- table %&gt;% select(!! (col_enquo), source, user_id) %&gt;%
      group_by_(!! (col_enquo), source) %&gt;% summarise(users = n_distinct(user_id)) %&gt;% 
      left_join(table %&gt;% group_by(source) %&gt;% 
                  summarise(total = n_distinct(user_id))) %&gt;% mutate(users/total)
    return(summary)
  }
  
  genderDemo &lt;- userCount(userMaster, city)
  
  </code></pre>
  
  <p>I get every type of error -</p>
  
  <pre><code>Error: `quos(desire)` must evaluate to column positions or names, not a list
  
  Error in !as_label(col_enquo) : invalid argument type 
  
  Error: Quosures can only be unquoted within a quasiquotation context.
  
    # Bad:
    list(!!myquosure)
  
    # Good:
    dplyr::mutate(data, !!myquosure)
  </code></pre>