-
Notifications
You must be signed in to change notification settings - Fork 997
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
merge.data.table() output is wrong #6804
Comments
Can confirm with both the CRAN version on R-4.2.2 and the current master branch on R-devel. Somehow
Edited your MRE a bit to (1) make it easier to copy&paste and (2) make sure all the relevant packages are attached. Part of the problem must be due to the data.table retaining the key after its rows are reordered by |
for a work-around please use [.data.table instead of merge |
I think I explicitly stated |
Evidently, a
The difference between While the cause of the problem is evident ( |
Possibly related: #5084. I haven't read carefully, but I wonder if adding an |
Either package can Enhance the other, providing #5084 is very relevant (and almost a palindrome of this issue number). We could try to make --- a/src/assign.c
+++ b/src/assign.c
@@ -256,8 +256,15 @@ SEXP alloccol(SEXP dt, R_len_t n, Rboolean verbose)
// names may be NULL when null.data.table() passes list() to alloccol for example.
// So, careful to use length() on names, not LENGTH().
if (length(names)!=l) internal_error(__func__, "length of names (%d) is not length of dt (%d)", length(names),l); // # nocov
- if (!selfrefok(dt,verbose))
- return shallow(dt,R_NilValue,(n>l) ? n : l); // e.g. test 848 and 851 in R > 3.0.2
+ if (!selfrefok(dt,verbose)) {
+ SEXP newdt = PROTECT(shallow(dt,R_NilValue,(n>l) ? n : l)); // e.g. test 848 and 851 in R > 3.0.2
+ // The attributes of non-intact data.tables are not to be trusted, so behave similarly
+ // to .shallow(x, retain.key = selfrefok(x)), like R shallow() does. #5084 #6804
+ setAttrib(newdt, sym_index, R_NilValue);
+ setAttrib(newdt, sym_sorted, R_NilValue);
+ UNPROTECT(1);
+ return newdt;
+ }
// added (n>l) ? ... for #970, see test 1481.
// TO DO: test realloc names if selfrefnamesok (users can setattr(x,"name") themselves for example.
// if (TRUELENGTH(getAttrib(dt,R_NamesSymbol))!=tl) |
#
Minimal reproducible example
; please be sure to setverbose=TRUE
where possible!Replacing
arrange()
withsetorder
resolves the issue.Removing any line among these 3 resolves the issue.
#
Output of sessionInfo()
The text was updated successfully, but these errors were encountered: