Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,8 @@

37. `as.IDate.POSIXct` returned `NA` for UTC times before Dec 1901 and after Jan 2038, [#3780](https://github.com/Rdatatable/data.table/issues/3780). Thanks @gschett for the report.

38. `rbindlist` now returns correct idcols for lists with different length vectors, [#3785](https://github.com/Rdatatable/data.table/issues/3785), [#3786](https://github.com/Rdatatable/data.table/pull/3786). Thanks to @shrektan for the report and fix.

#### NOTES

1. `rbindlist`'s `use.names="check"` now emits its message for automatic column names (`"V[0-9]+"`) too, [#3484](https://github.com/Rdatatable/data.table/pull/3484). See news item 5 of v1.12.2 below.
Expand Down
8 changes: 8 additions & 0 deletions inst/tests/tests.Rraw
Original file line number Diff line number Diff line change
Expand Up @@ -15840,6 +15840,14 @@ test(2093.2, hour(date), 0L)
test(2093.3, minute(date), 0L)
test(2093.4, second(date), 0L)

# correct rbindlist() idcol for list elements with different length, #3785
x = 1:100
X = rbindlist(lapply(x, function(.) list(., 1:2, 2:3)), idcol = 'TAG')
test(2094.01, X$TAG, rep(x, each = 2))
x = setNames(x, paste0("nm_", x))
X = rbindlist(lapply(x, function(.) list(., 1:2, 2:3)), idcol = 'TAG')
test(2094.02, X$TAG, rep(names(x), each = 2))


###################################
# Add new tests above this line #
Expand Down
4 changes: 2 additions & 2 deletions src/rbindlist.c
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ SEXP rbindlist(SEXP l, SEXP usenamesArg, SEXP fillArg, SEXP idcolArg)
for (int i=0,ansloc=0; i<LENGTH(l); ++i) {
SEXP li = VECTOR_ELT(l, i);
if (!length(li)) continue;
const int thisnrow = length(VECTOR_ELT(li, 0));
const int thisnrow = eachMax[i];
SEXP thisname = STRING_ELT(listNames, i);
for (int k=0; k<thisnrow; ++k) SET_STRING_ELT(idval, ansloc++, thisname);
}
Expand All @@ -261,7 +261,7 @@ SEXP rbindlist(SEXP l, SEXP usenamesArg, SEXP fillArg, SEXP idcolArg)
for (int i=0,ansloc=0; i<LENGTH(l); ++i) {
SEXP li = VECTOR_ELT(l, i);
if (!length(li)) continue;
const int thisnrow = length(VECTOR_ELT(li, 0));
const int thisnrow = eachMax[i];
for (int k=0; k<thisnrow; ++k) idvald[ansloc++] = i+1;
}
}
Expand Down