[datatable-help] data.table 1.8.2: Problem using by= and a key that doesn't match any rows in the table

Michael Schermerhorn mscherme at google.com
Mon Aug 6 19:13:53 CEST 2012


Thank you.

On Mon, Aug 6, 2012 at 10:05 AM, Matthew Dowle <mdowle at mdowle.plus.com>wrote:

>
> Yes this is a bug, already reported:  #2162 "Internal error with
> simultanous join (with missing groups) and group by in 1.8.2"
>
>
> https://r-forge.r-project.org/tracker/index.php?func=detail&aid=2162&group_id=240&atid=975
>
> Will fix and add tests.  Thanks for reporting.  Have added link to your
> example to the report.
>
> Matthew
>
> > I recently updated from data.table 1.7.1 to 1.8.2 and found that my old
> > code using data.table
> > no longer works.  I'm not sure if this is being caused by a bug in the
> new
> > version of data.table
> > or an intentional change to the way data.table works.
> >
> > In 1.7.1, I could do the following:
> >> DT <- data.table(x=rep(c("a","b","c"),each=3), y=c(1,3,6), v=1:9)
> >> setkey(DT, x)
> >> DT[J(c("a", "b", "d")), sum(v), by=x]
> >         x V1
> > [1,]    a  6
> > [2,]    b 15
> > [3,] <NA> NA
> >
> >
> > In 1.8.2, however, I get an error message:
> >> DT <- data.table(x=rep(c("a","b","c"),each=3), y=c(1,3,6), v=1:9)
> >> setkey(DT, x)
> >> DT[J(c("a", "b", "d")), sum(v), by=x]
> > Error in if (any(irows < 1L | irows > nrow(x))) stop("Internal error:
> some
> > irows<1 or >nrow(x)") :
> >   missing value where TRUE/FALSE needed
> >
> >
> > Looking through the NEWS file I don't see any mention of this change
> (It's
> > possible that I just missed it).
> > If this an intentional change, I would ask that you consider reverting
> it.
> >  It seems inconsistent that
> > DT[J(c("a", "b", "d"))] adds a new row to the table, but DT[J(c("a", "b",
> > "d")), sum(v), by=x]
> > causes an error.
> >
> > Personally I think the following makes the most sense.  But just
> reverting
> > back to what it did in 1.7.1
> > seems better than having an error.
> >> DT[J(c("a", "b", "d")), sum(v), by=x]
> >      x V1
> > [1,] a  6
> > [2,] b 15
> > [3,] d NA
> >
> >
> > Thank you,
> > Mike
> > _______________________________________________
> > 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
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/datatable-help/attachments/20120806/32e1ffea/attachment-0001.html>


More information about the datatable-help mailing list