title: unquote string as variable in pipe
body: <p>I want to remove duplicate rows from a dataframe, for specific columns only. That can be obtained with <code>distinct</code>:</p>
  
  <pre><code>data &lt;- tibble(a = c(1, 1, 2, 2), b = c(3, 3, 3, 4), z = c(5,4,5,5))
  filtered_data &lt;- data %&gt;% distinct(a, b, .keep_all = T)
  dim(filtered_data)  
  # [1] 3 3
  </code></pre>
  
  <p>This is (almost) what I need. Yet, my problem is that the columnnames I need to use with <code>distinct</code> will change. So I have a string <code>gen</code> that contains the names of the columns I want to use for with the <code>distinct</code> function. They need to get unquoted to be usefull in the pipe. I found suggestions to use <code>as.name()</code> or <code>eval(parse())</code>. This however gives me a different result:</p>
  
  <pre><code>gen &lt;- c("a", "b")
  filtered_data &lt;- data %&gt;% distinct(eval(parse(text = gen)), .keep_all = T)
  dim(filtered_data)  
  # [1] 2 4
  </code></pre>
  
  <p>The <code>eval</code> seems to do something funny with the amount of times the data is filtered. (and, adds an extra column. I could live with that, though...) So, how to obtain a similar result, as if I had used <code>a,b</code>, but by using a variable instead?</p>
  
  <p><strong>additional information</strong>
  I actually obtain <code>gen</code> by reading the columnnames of a dataframe: <code>gen &lt;- colnames(data)[1:2]</code>. The solution suggested by @gymbrane would be perfect, if I had a way to transform the <code>gen</code> to <code>c(a, b)</code>. The whole point is to avoid hardcoding the columnames. I tried things like <code>gen &lt;- noquotes(gen)</code>, which does not give an error in the <code>rm_dup_rows</code> function suggested below, but it does give a different result, giving the same sort of repeated filtering as I started with...</p>
  
  <p><strong>fixed</strong>
  I think I got it working. It might be unelegant, and I'm not sure if every step is necessary for the result, but it seems to work by combining the function provided by @gymbrane below with <code>ensym</code> and <code>quos</code> in a forloop while adding to a list <s>in <code>GlobalEnv</code></s> (edit: GlobalEnv isn't necessary):</p>
  
  <pre><code>unquote_string &lt;- function(string) {
    out &lt;- list()
    i &lt;- 1
    for (s in string) {
      t &lt;- ensym(s)
      out[i] &lt;-dplyr::quos(!!t)
      i &lt;- i+1
    }
  return(out)
  }
  gen_quo &lt;- unquote_string(gen)
  filtered_data &lt;- rm_dup_rows(data, gen_quo)
  dim(filtered_data)
  # [1] 3 3 
  </code></pre>