using NSE on spread_ in R tidyr <p>Using the following dataset:</p> <pre><code>temp &lt;- structure(list( GENDER = structure(c(1L, 1L, 1L, 2L, 1L, 1L, 1L, 2L, 2L, 2L), .Label = c("F", "M"), class = "factor"), EVERFSM_6 = c(0L, 0L, 0L, 1L, 0L, 1L, 0L, 1L, 0L, 1L), `0001` = c(0, 11, 22, 33, 33, 55, 66, 77, 88, 0), n = c(20L, 13L, 4L, 13L, 36L, 94L, 28L, 50L, 27L, 1L)), .Names = c("GENDER", "EVERFSM_6", "0001", "n"), class = c("tbl_df", "data.frame"), row.names = c(NA, -10L)) </code></pre> <p>And I'm trying to perform the following <a href="http://search.r-project.org/library/tidyr/html/spread_.html" rel="nofollow">spread_</a> operation to summarise the data:</p> <pre><code>DiscID &lt;- "0001" colID &lt;- as.name(DiscID) cols &lt;- c("GENDER", colID, "n") gender_results &lt;- temp %&gt;% select_(.dots=cols) %&gt;% group_by_(.dots=cols[1:2]) %&gt;% summarise(gender_n = sum(n)) %&gt;% spread_(paste0("`",DiscID,"`"), "gender_n") %&gt;% rename(type = GENDER) </code></pre> <p>But it says:</p> <pre><code>Error: Key column '`0001`' does not exist in input. </code></pre> <p>I'm having to use the _ version of select_, group_by_ and spread_ as I am using a variable to refer to column names. The desired output is below, achievable by using the hard coded:</p> <pre><code>spread(`0001`, gender_n) %&gt;% type 0 11 22 33 55 66 77 88 (fctr) (int) (int) (int) (int) (int) (int) (int) (int) 1 F 20 13 4 36 94 28 NA NA 2 M 1 NA NA 13 NA NA 50 27 </code></pre>