title: How to use UQ in the RHS of assignment operator involving base R functions when using dplyr?
body: <p>I would like to use variables with varying names (i.e. names defined by using arguments of the function) in the calculations on RHS of assignment operators. Base R functions (<code>min</code>, <code>max</code>, etc.) interpret the result of the unquoting operand <code>!!</code> as string, which is not what I want. How should I specify that R should work with variables names, not strings. No problem when using <code>!!</code> with dplyr verbs, such as <code>select</code>, <code>mutate</code>, etc. </p>
  
  <pre><code>
  df &lt;- tibble(
    g1 = c(1, 1, 2, 2, 2),
    g2 = c(1, 2, 1, 2, 1),
    a = sample(5),
    b = sample(5)
  )
  
  my_s_mutate &lt;- function(df, group_var, expr) {
  
    group_var &lt;- enquo(group_var)
    expr &lt;- enquo(expr)
    mean_name &lt;- paste0("mean_", quo_name(expr))
    sum_name &lt;- paste0("sum_", quo_name(expr))
  
    df %&gt;%
      group_by(!! group_var) %&gt;%
      mutate(
           !! mean_name := mean(!! expr),
           !! sum_name := sum(!! expr),
           diff = !! sum_name - !! mean_name
    )
  }
  
  my_s_mutate(df, g1, a)
  </code></pre>
  
  <p>This code give error because is evaluating the difference between two strings. Similar problem occurs when using <code>min</code> or <code>max</code></p>
  
  <pre><code> Error in "sum_a" - "mean_a" : non-numeric argument to binary operator 
  </code></pre>
  
  <p>Any ideas how to solve the problem!!!</p>