Skip to content

Commit 633206f

Browse files
split out setcbindlist
1 parent 6afd693 commit 633206f

File tree

3 files changed

+14
-11
lines changed

3 files changed

+14
-11
lines changed

NAMESPACE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ export(nafill)
5959
export(setnafill)
6060
export(.Last.updated)
6161
export(fcoalesce)
62-
export(cbindlist)
62+
export(cbindlist, setcbindlist)
6363
export(substitute2)
6464
#export(DT) # mtcars |> DT(i,j,by) #4872 #5472
6565
export(fctr)

R/mergelist.R

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
cbindlist = function(l, copy=TRUE) {
1+
cbindlist_impl_ = function(l, copy) {
22
ans = .Call(Ccbindlist, l, copy)
33
if (anyDuplicated(names(ans))) { ## invalidate key and index
44
setattr(ans, "sorted", NULL)
@@ -7,3 +7,6 @@ cbindlist = function(l, copy=TRUE) {
77
setDT(ans)
88
ans
99
}
10+
11+
cbindlist = function(l) cbindlist_impl_(l, copy=TRUE)
12+
setcbindlist = function(l) cbindlist_impl_(l, copy=FALSE)

inst/tests/mergelist.Rraw

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ if (exists("test.data.table", .GlobalEnv, inherits=FALSE)) {
88
test = data.table:::test
99
}
1010

11-
# cbindlist
11+
# cbindlist, setcbindlist
1212

1313
local({
1414
l = list(
@@ -20,7 +20,7 @@ local({
2020
expected = data.table(l$d1, l$d2, l$d3)
2121
test(11.01, ans, expected)
2222
test(11.02, intersect(vapply(ans, address, ""), unlist(lapply(l, vapply, address, ""))), character())
23-
ans = cbindlist(l, copy=FALSE)
23+
ans = setcbindlist(l)
2424
expected = setDT(c(l$d1, l$d2, l$d3))
2525
test(11.03, ans, expected)
2626
test(11.04, length(intersect(vapply(ans, address, ""), unlist(lapply(l, vapply, address, "")))), ncol(expected))
@@ -49,8 +49,8 @@ test(12.12, cbind(data.table(x=integer()), data.table(a=1:2)), data.table(x=c(NA
4949
test(12.13, cbind(data.table(x=1L), data.table(a=1:2)), data.table(x=c(1L, 1L), a=1:2))
5050
test(12.14, cbindlist(list(data.table(a=integer()), data.table(b=1:2))), error="Recycling.*not yet implemented")
5151
test(12.15, cbindlist(list(data.table(a=1L), data.table(b=1:2))), error="Recycling.*not yet implemented")
52-
test(12.16, cbindlist(list(data.table(a=integer()), data.table(b=1:2)), copy=FALSE), error="have to have the same number of rows")
53-
test(12.17, cbindlist(list(data.table(a=1L), data.table(b=1:2)), copy=FALSE), error="have to have the same number of rows")
52+
test(12.16, setcbindlist(list(data.table(a=integer()), data.table(b=1:2))), error="have to have the same number of rows")
53+
test(12.17, setcbindlist(list(data.table(a=1L), data.table(b=1:2))), error="have to have the same number of rows")
5454

5555
## retain indices
5656
local({
@@ -63,9 +63,9 @@ local({
6363
setkeyv(l[[1L]], "id1"); setindexv(l[[1L]], list("id1", "id2", "id3", c("id1","id2","id3"))); setindexv(l[[3L]], list("id6", "id7")); setindexv(l[[4L]], "id9")
6464
ii = lapply(l, indices)
6565
ans = cbindlist(l)
66-
test(13.04, key(ans), "id1")
67-
test(13.05, indices(ans), c("id1", "id2", "id3", "id1__id2__id3", "id6", "id7", "id9"))
68-
test(13.06, ii, lapply(l, indices)) ## this tests that original indices have not been touched, shallow_duplicate in mergeIndexAttrib
66+
test(13.01, key(ans), "id1")
67+
test(13.02, indices(ans), c("id1", "id2", "id3", "id1__id2__id3", "id6", "id7", "id9"))
68+
test(13.03, ii, lapply(l, indices)) ## this tests that original indices have not been touched, shallow_duplicate in mergeIndexAttrib
6969
})
70-
test(13.07, cbindlist(list(data.table(a=1:2), data.table(b=3:4, key="b"))), data.table(a=1:2, b=3:4, key="b"))
71-
# test(13.08, cbindlist(list(data.table(a=1:2, key="a"), data.table(b=3:4, key="b"))), data.table(a=1:2, b=3:4, key=c("a", "b")))
70+
test(13.04, cbindlist(list(data.table(a=1:2), data.table(b=3:4, key="b"))), data.table(a=1:2, b=3:4, key="b"))
71+
# test(13.05, cbindlist(list(data.table(a=1:2, key="a"), data.table(b=3:4, key="b"))), data.table(a=1:2, b=3:4, key=c("a", "b")))

0 commit comments

Comments
 (0)