title: Error in eval(bysub, x, parent.frame()) : object 'Year' not found
body: <p>I am trying to write a function using R data.table syntax. It has results if I just run this line <code>countbyYr = data[, .(counts = uniqueN(Col_A)), by = .(Year)]</code>, but once I put it into a function (shown below), it'll tell me <code>Error in eval(bysub, x, parent.frame()) : object 'Year' not found</code>.</p>
  <pre><code>counts_func &lt;- function(df,groupby_col) {
    cnts&lt;- df[, .(counts = uniqueN(Col_A)), by = .(groupby_col)]
    return(cnts)
  }
  countbyYr = counts_func(data,Year)
  </code></pre>
  <p>I've tried adding <code>get()</code> to get the column variable as some posts suggested, however, I'm still getting error messages.</p>