<div dir="ltr">I think I found a bug, either in the code that combines the results from grouping with 'by' or in the comparison code for IDate.  The following is a simplified description of where and how, where the names have been<div>
changed to protect innocent variables.</div><div><br><div>My code runs a function f on a data.table like so:<div><br></div><div>output <- DT[, f(a.date, b.date, etc), by = group]</div><div><br></div><div>The function f returns a data.table f.out with four columns, two of which are dates.  All dates are stored as IDate, and the dates themselves are</div>
<div>never changed or altered; some are relevant and most aren't.  Explicitly</div><div>printing the class of each column via</div><div><br></div><div>print(sapply(f.out, class))</div><div><br></div><div>in f before returning always identifies the same classes, in my case</div>
<div>"IDate" "Date", "IDate" "Date", "numeric", "integer"</div><div><br></div><div>Despite this, for a certain group, I get the error</div><div><br></div><div>columns of j don't evaluate to consistent types for each group: result for group 17 has column 1 type 'double' but expecting type 'integer'</div>
<div><br></div><div>Every attempt to identify the problem with group 17 failed; its output</div><div>looks perfectly correct, and everything checks out, even in debug.</div><div>Using as.IDate explicitly anywhere before or during making the data.table f.out fixes the problem.</div>
<div><br></div><div>As an aside, the error message above is not very helpful in general;</div><div>I'd like to see *exactly* what isn't matching and where it's coming</div><div>from.  As another aside, when I run code like this, it's often the case</div>
<div>that some groups don't end up belonging in the output at all.  I can't</div><div>figure out how to clue data.table to this; I'd like to just return NULL</div><div style>and that group not be in the output.  Instead, I'm currently returning</div>
<div style>a row of obviously wrong output and filtering them later.  Is there something I'm missing?</div><div><div>-------<br>Nathaniel Graham<br><a href="mailto:npgraham1@gmail.com" target="_blank">npgraham1@gmail.com</a><br>
<a href="mailto:npgraham1@uky.edu" target="_blank">npgraham1@uky.edu</a></div>
</div></div></div></div>