title: R: dplyr "must be a 1d atomic vector or a list" error when using filter_()
body: <p>I have a <code>data.frame</code> in R called <code>possibleVotes</code> which looks like this (see end of post for code that generated this data frame, or CSV table <a href="https://pastebin.com/tfz4VM37" rel="nofollow noreferrer">here</a>):</p>
  
  <pre><code>+------+------+------+------+------+-------------+--------+------+
  | Var1 | Var2 | Var3 | Var4 | Var5 | nSuccesses1 | p1     | use1 |
  +------+------+------+------+------+-------------+--------+------+
  | 0    | 0    | 0    | 1    | 0    | 0           | 0.0225 | 0    |
  +------+------+------+------+------+-------------+--------+------+
  | 1    | 0    | 0    | 1    | 0    | 1           | 0.1275 | 0    |
  +------+------+------+------+------+-------------+--------+------+
  | 0    | 1    | 0    | 1    | 0    | 1           | 0.1275 | 0    |
  +------+------+------+------+------+-------------+--------+------+
  | 1    | 1    | 0    | 1    | 0    | 2           | 0.7225 | 1    |
  +------+------+------+------+------+-------------+--------+------+
  </code></pre>
  
  <p>I'm trying to use <code>dplyr</code> to filter it with code like this:</p>
  
  <pre><code>round &lt;- 1
  roundTotal &lt;- 2
  
  pRound1 &lt;- possibleVotes %&gt;%
      select_(num_range("Var", 1:2), paste0("nSuccesses", round), paste0("p", round), paste0("use", round)) %&gt;%
      distinct_() %&gt;%
      filter_(paste0("nSuccesses", round) == roundTotal &amp; paste0("use", round) == 1) %&gt;%
      select_(paste0("p", round)) %&gt;%
      sum()
  </code></pre>
  
  <p>My expected results is simply that <code>pRound1</code> would be 0.7225. Unfortunately I get this error:</p>
  
  <blockquote>
    <p>Error: Column <code>p1</code> must be a 1d atomic vector or a list</p>
  </blockquote>
  
  <p>I went through each step and discovered that:</p>
  
  <ol>
  <li>There is no error up and through <code>distinct_()</code>.</li>
  <li>The error shows up at the <code>filter_()</code> step.</li>
  <li><code>num_range()</code> did not work (the columns <code>Var1</code> and <code>Var2</code> were not selected)</li>
  </ol>
  
  <p>I have no idea what the error means, and don't know why <code>num_range()</code>  did not give me the desired results either...</p>
  
  <p>How do I troubleshoot this? Thanks!</p>
  
  <p>EDIT: After generous help from @Axeman, I tried this for <code>filter_()</code>:</p>
  
  <pre><code>filter_(lazyeval::interp(~a == b, a = as.name(paste0("nSuccesses", round)), b = roundTotal)) %&gt;% 
  filter_(lazyeval::interp(~a == b, a = as.name(paste0("use", round)), b = 1))
  </code></pre>
  
  <p>Unfortunately it still gives this:</p>
  
  <blockquote>
    <p>Error: Column <code>p1</code> must be a 1d atomic vector or a list</p>
  </blockquote>
  
  <p>EDIT 2: I'm running dplyr 0.5.0 with R 3.4.0.</p>
  
  <p>EDIT 3: Here is the complete code I used to generate the original <code>possibleVotes</code> data frame:</p>
  
  <pre><code>possibleVotes &lt;- expand.grid(replicate(5, c(0,1), simplify = FALSE))
  
  pSpecies &lt;- 0.85
  round &lt;- 1
  roundFor &lt;- 2
  roundAgainst &lt;- 0
  roundTotal &lt;- roundFor + roundAgainst
  
  possibleVotes[paste0("nSuccesses", round)] &lt;- rowSums(possibleVotes[1:roundTotal])
  possibleVotes[paste0("p", round)] &lt;- pSpecies^(possibleVotes[paste0("nSuccesses", round)]) * (1-pSpecies)^(round1Total - possibleVotes[paste0("nSuccesses", round)])
  
  possibleVotes[paste0("use", round)] &lt;- apply(possibleVotes, 1, function(x) if (sum(x[1:roundTotal]) == roundFor) 1 else 0)
  </code></pre>