[datatable-help] bug in 'consistent types for each group' code?
Nathaniel Graham
npgraham1 at gmail.com
Mon May 6 10:20:11 CEST 2013
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
changed to protect innocent variables.
My code runs a function f on a data.table like so:
output <- DT[, f(a.date, b.date, etc), by = group]
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
never changed or altered; some are relevant and most aren't. Explicitly
printing the class of each column via
print(sapply(f.out, class))
in f before returning always identifies the same classes, in my case
"IDate" "Date", "IDate" "Date", "numeric", "integer"
Despite this, for a certain group, I get the error
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'
Every attempt to identify the problem with group 17 failed; its output
looks perfectly correct, and everything checks out, even in debug.
Using as.IDate explicitly anywhere before or during making the data.table
f.out fixes the problem.
As an aside, the error message above is not very helpful in general;
I'd like to see *exactly* what isn't matching and where it's coming
from. As another aside, when I run code like this, it's often the case
that some groups don't end up belonging in the output at all. I can't
figure out how to clue data.table to this; I'd like to just return NULL
and that group not be in the output. Instead, I'm currently returning
a row of obviously wrong output and filtering them later. Is there
something I'm missing?
-------
Nathaniel Graham
npgraham1 at gmail.com
npgraham1 at uky.edu
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/datatable-help/attachments/20130506/abb3f9ac/attachment.html>
More information about the datatable-help
mailing list