title: Getting "unused argument" when summarising a dataframe
body: <p>I know nothing/zip/nada about programming in R, but we have been asked to run some code that summarizes a data frame (data table? not sure of lingo).  I am getting an error thrown on a particular line, and my googling isn't teaching me enough about R syntax for me to figure it out.</p>
  
  <p>I am stepping through the R code using <em>RStudio v1.2.1335</em>, and the R version is <em>R x64 3.6.1</em></p>
  
  <p>A dataframe <em>dff</em> is created that contains a bunch of columns and has half hourly data for various nodes for approximately 4 years.  As a very simplified demo without all the columns something like:</p>
  
  <pre><code>datetime        node   year   load, generation, deltaSS ...
  1/1/2014 00:00, ABC,   2014,   100,  50,          300    ...
  1/1/2014 00:00, XYZ,   2014,   200,  150,         500    ...
  1/1/2014 00:30, ABC,   2014,   125,  70,          355    ...
  1/1/2014 00:30, ABC,   2014,   220,  150,         25     ...
  :
  1/1/2015 00:00, ABC,   2015,   200,  20,          200    ...
  1/1/2015 00:00, XYZ,   2015,   400,  450,         400    ...
  :
  </code></pre>
  
  <p>What I believe the code is trying to do is summarize a subset of these columns for specific groupings.  Some of the columns need to be simple summed, others need to be summed / 2 to convert into a different unit.  The grouping is by year and by node.</p>
  
  <p>In other words, for each year and node, sum up (or sum/2) the values of some of the columns in the table.  Something like:</p>
  
  <pre><code>node   year   load, generation, deltaSS ...
  ABC,   2014,   1000,  5000,     30000    ...
  XYZ,   2014,   2000,  15000,    50000    ...
  ABC,   2014,   1250,  7000,     35500    ...
  ABC,   2014,   2200,  15000,    2500     ...
  :
  ABC,   2015,   2000,  2000,     20000    ...
  XYZ,   2015,   4000,  45000,    40000    ...
  :
  </code></pre>
  
  <p>The error I am getting is:</p>
  
  <p><strong>Error in <code>[.data.frame</code>(dff, , .(generationMWh = sum(generation)/2, loadMWh = sum(load,  : 
    unused argument (by = .(modelyear, node))</strong></p>
  
  <p>It seems strange that we're getting an error at all because apparently this code has been run and works (I only mention this in case it turns out to be a library version or something).</p>
  
  <p>The code that throws the error is:</p>
  
  <pre><code>df &lt;- dff[,.(generationMWh = sum(generation)/2, 
                   loadMWh = sum(load,na.rm = TRUE)/2,
                   deltaSS = sum(deltaSS,na.rm = TRUE), 
                   pos_deltaSS = sum(pos_deltaSS,na.rm = TRUE), 
                   neg_deltaSS = sum(neg_deltaSS,na.rm = TRUE), 
                   deltaCS = sum(deltaCS,na.rm = TRUE),
                   pos_deltaCS = sum(pos_deltaCS,na.rm = TRUE),
                   neg_deltaCS = sum(neg_deltaCS,na.rm = TRUE)
      ), by = .(modelyear,node)]
  </code></pre>
  
  <p>Can someone help me out here?   Perhaps if its not immediately obvious what the problem is, could there be another way to write R code that summarizes specific columns by groupings?</p>
  
  <p>Thanks in advance
  Andy C</p>
  
  <p><strong>EDIT</strong>
  I have subsequently figured out that I can get this code to work if I convert the <em>data.frame</em> to a <em>data.table</em> before running the summarizing code:</p>
  
  <pre><code>dff &lt;- as.data.table(dff)
  </code></pre>
  
  <p>Whether this code was successfully run previously is now in question, but at least we can move forward.</p>