[datatable-help] IDate goes from int to num (easier example this time, and does not rely on plyr).

Matthew Dowle mdowle at mdowle.plus.com
Tue Aug 16 20:32:35 CEST 2011


I tried [<-.IDate and also c.IDate but no joy. Not sure what's going on.

Anyway, it turned out to be a bit of a red herring as there was a larger
issue. This fixes it (committed to v1.6.5) : 

o   Numeric columns with class attributes are now correctly
    coerced to integer by setkey and ad hoc by. The error
    similar to 'fractional data is being truncated' should now
    only occur when that really is true. A side effect of
    this is that ad hoc by and setkey now work on IDate columns
    which have somehow become numeric; e.g. via rbind(DF,DF)
    as reported by Chris Neff.

Matthew


On Mon, 2011-08-08 at 17:08 -0400, Tom Short wrote:
> That narrowed it done a lot. Thanks, Chris. It looks like we need a
> "[<-.IDate"  function. You can use the following locally until we can
> get data.table updated.
> 
> "[<-.IDate" <-  function(x, ...) {
>         as.IDate(NextMethod())
> }
> 
> Let me know if that doesn't fix it for you. Please also check to see
> if this fixes the ddply issue.
> 
> - Tom
> 
> On Mon, Aug 8, 2011 at 8:17 AM, Chris Neff <caneff at gmail.com> wrote:
> > Hi all,
> >
> > Using the latest 1.6.4 with type="source" from R-Forge.  The issue
> > seems to be with rbind on a data frame. Here's what happens:
> >
> >> DT <- data.frame(x=as.IDate(rep("2010-01-01",10)), y=1:10)
> >> str(DT)
> > 'data.frame':   10 obs. of  2 variables:
> >  $ x:Classes 'IDate', 'Date'  int [1:10] 14610 14610 14610 14610 14610
> > 14610 14610 14610 14610 14610
> >  $ y: int  1 2 3 4 5 6 7 8 9 10
> >> str(rbind(DT, DT))
> > 'data.frame':   20 obs. of  2 variables:
> >  $ x:Classes 'IDate', 'Date'  num [1:20] 14610 14610 14610 14610 14610 ...
> >  $ y: int  1 2 3 4 5 6 7 8 9 10 ...
> >
> > If I take rbind(DT, DT), make it into a data table, and try to set the
> > key as x, it gives an error that x cannot be converted into integer
> > without losing some information.  That is because as you see from the
> > str calls above, x turns from "Classes 'IDate', 'Date' int" to
> > "Classes 'IDate', 'Date' num".
> >
> > Note that rbind(data.table(DT), data.table(DT)) works fine.  So it is
> > the interaction between IDate and rbind.data.frame. Tried skimming
> > rbind.data.frame for any obvious things that stick out, but that is a
> > pretty inscrutable function.
> >
> > Thoughts?
> > -Chris
> > _______________________________________________
> > datatable-help mailing list
> > datatable-help at lists.r-forge.r-project.org
> > https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/datatable-help
> >
> _______________________________________________
> datatable-help mailing list
> datatable-help at lists.r-forge.r-project.org
> https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/datatable-help




More information about the datatable-help mailing list