Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
sebastian-c opened this issue Sep 22, 2015 · 3 comments
Closed

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

sebastian-c opened this issue Sep 22, 2015 · 3 comments
Assignees
Labels
Milestone

Comments

@sebastian-c
Copy link

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.

@franknarf1
Copy link
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.

@arunsrinivasan arunsrinivasan added this to the v1.9.8 milestone Sep 22, 2015
@arunsrinivasan arunsrinivasan self-assigned this Sep 22, 2015
@arunsrinivasan
Copy link
Member

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

@sebastian-c
Copy link
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
Labels
Projects
None yet
Development

No branches or pull requests

3 participants