Skip to content

Data tables won't merge if by argument has names #1352

Closed

Description

@sebastian-c

I've been trying the merge some data tables, but it seems that if the 'by' argument has names, they won't merge, giving an error:

Error in forderv(x, by = rightcols) : 'by' value -2147483648 out of range [1,8]

I've managed to make as small an example as I can to reproduce the error:

tab1 <- structure(list(a = c(1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 
3L, 3L, 3L, 3L, 3L, NA), b = c(2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 
2, 2, 2, 2, 2, NA), c = c(2010L, 2011L, 2012L, 2013L, 2014L, 
2010L, 2011L, 2012L, 2013L, 2014L, 2010L, 2011L, 2012L, 2013L, 
2014L, NA), d = c(-0.625996555127917, 0.325673822554901, 1.68461340609045, 
-2.09358233735785, -0.444517113337327, 0.247434396526436, -0.595608214998598, 
0.779085729216547, 0.343640797995949, -1.03199833192338, 0.499177323692263, 
0.142404120359858, 0.124892949669588, 0.28962454726758, 1.45581442296567, 
1.27173157262308), e = c(NA, NA, NA, NA, NA, NA, NA, NA, NA, 
NA, NA, NA, NA, NA, NA, NA), f = c(NA, NA, NA, NA, NA, NA, NA, 
NA, NA, NA, NA, NA, NA, NA, NA, NA), g = c(NA, NA, NA, NA, NA, 
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA), h = c(1.82940602609317, 
0.337391723803077, 1.49770018138232, -0.353146958400835, 1.09995073678083, 
-0.578792240046591, 1.55076285478448, 0.919702101279719, 1.91852234353312, 
0.902454834121264, -1.37138551168091, 0.416357331689734, 0.306641948600609, 
-1.1230027058004, -0.621123012856139, 0.645928414645345)), .Names = c("a", 
"b", "c", "d", "e", "f", "g", "h"), row.names = c(NA, -16L), class = "data.frame")

tab2 <- structure(list(a = c(1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 
3L, 3L, 3L, 3L, 3L, NA), b = c(2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 
2, 2, 2, 2, 2, NA), c = c(2010L, 2011L, 2012L, 2013L, 2014L, 
2010L, 2011L, 2012L, 2013L, 2014L, 2010L, 2011L, 2012L, 2013L, 
2014L, NA), D = structure(c(1L, 1L, 1L, 1L, 2L, 1L, 1L, 1L, 1L, 
2L, 1L, 1L, 1L, 1L, 2L, NA), .Label = c("", "M"), class = "factor"), 
    E = c(NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
    NA, NA, NA), F = c(NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
    NA, NA, NA, NA, NA, NA), G = c(NA, NA, NA, NA, NA, NA, NA, 
    NA, NA, NA, NA, NA, NA, NA, NA, NA), H = structure(c(1L, 
    1L, 1L, 1L, 2L, 1L, 1L, 1L, 1L, 2L, 1L, 1L, 1L, 1L, 2L, NA
    ), .Label = c("", "M"), class = "factor")), .Names = c("a", 
"b", "c", "D", "E", "F", "G", "H"), row.names = c(NA, -16L), class = "data.frame")

tab1 <- data.table(tab1)
tab2 <- data.table(tab2)

keys <- c("a", "b", "c")

merge(tab1, tab2, by=keys)
names(keys) <- letters[24:26]

merge(tab1, tab2, by=keys)

Notice that the first merge works, but the second merge gives the aforementioned error.

Activity

  1. franknarf1 commented on Sep 22, 2015

    @franknarf1
    Contributor

    If you instead use

    names(keys) <- keys
    

    the merge goes through fine. Presumably, the the names are used in some (as yet undocumented) way. You could mess around with permutations, like

    names(keys) <- rev(keys)
    

    to uncover what's going on.

  2. added this to the v1.9.8 milestone on Sep 22, 2015
  3. arunsrinivasan commented on Sep 23, 2015

    @arunsrinivasan
    Member

    Thanks for the nice reprex @sebastian-c, should be fixed now. Please verify.

  4. sebastian-c commented on Sep 28, 2015

    @sebastian-c
    Author

    Confirmed, the bug has been fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions