@@ -21042,28 +21042,30 @@ test(2304.100, set(copy(DT), i=2L, j=c("L1", "L2"), value=list(list(NULL), list(
2104221042# the integer overflow in #6729 is only noticeable with UBSan
2104321043test(2305, { fread(testDir("issue_6729.txt.bz2")); TRUE })
2104421044
21045- # sort_by.data.table
21046- DT1 = data.table(a=c(1, 3, 2, NA, 3), b=4:0)
21047- DT2 = data.table(a=c("c", "a", "B")) # data.table uses C-locale and should sort_by if cedta()
21048- DT3 = data.table(a=c(1, 2, 3), b=list(c("a", "b", "", NA), c(1, 3, 2, 0), c(TRUE, TRUE, FALSE, NA))) # list column
21049-
21050- # sort_by.data.table: basics
21051- test(2306.01, sort_by(DT1, ~a + b), data.table(a=c(1, 2, 3, 3, NA), b=c(4L, 2L, 0L, 3L, 1L)))
21052- test(2306.02, sort_by(DT1, ~I(a + b)), data.table(a=c(3, 2, 1, 3, NA), b=c(0L, 2L, 4L, 3L, 1L)))
21053- test(2306.03, sort_by(DT2, ~a), data.table(a=c("B", "a", "c")))
21054-
21055- # sort_by.data.table: list columns.
21056- # NOTE 1: .formula2varlist works well with list columns.
21057- # NOTE 2: 4 elem in DT of 3 row because forderv takes a list column as a DT.
21058- test(2306.04, sort_by(DT3, ~b), DT3[order(b)]) # should be consistent.
21059-
21060- # sort_by.data.table: additional C-locale sorting
21061- test(2306.10, DT2[, sort_by(.SD, a)], data.table(a=c("B", "a", "c")))
21062- test(2306.11, DT2[, sort_by(.SD, ~a)], data.table(a=c("B", "a", "c")))
21063-
21064- # sort_by.data.table: various working interfaces
21065- test(2306.20, sort_by(DT1, list(DT1$a, DT1$b)), data.table(a=c(1, 2, 3, 3, NA), b=c(4L, 2L, 0L, 3L, 1L)))
21066- test(2306.21, sort_by(DT1, DT1[, .(a, b)]), data.table(a=c(1, 2, 3, 3, NA), b=c(4L, 2L, 0L, 3L, 1L)))
21067- test(2306.22, DT1[, sort_by(.SD, .(a, b))], data.table(a=c(1, 2, 3, 3, NA), b=c(4L, 2L, 0L, 3L, 1L)))
21068- test(2306.23, DT1[, sort_by(.SD, ~a + b)], data.table(a=c(1, 2, 3, 3, NA), b=c(4L, 2L, 0L, 3L, 1L)))
21069- test(2306.24, DT1[, sort_by(.SD, ~.(a, b))], data.table(a=c(1, 2, 3, 3, NA), b=c(4L, 2L, 0L, 3L, 1L)))
21045+ if (exists("sort_by", "package:base")) {
21046+ # sort_by.data.table
21047+ DT1 = data.table(a=c(1, 3, 2, NA, 3), b=4:0)
21048+ DT2 = data.table(a=c("c", "a", "B")) # data.table uses C-locale and should sort_by if cedta()
21049+ DT3 = data.table(a=c(1, 2, 3), b=list(c("a", "b", "", NA), c(1, 3, 2, 0), c(TRUE, TRUE, FALSE, NA))) # list column
21050+
21051+ # sort_by.data.table: basics
21052+ test(2306.01, sort_by(DT1, ~a + b), data.table(a=c(1, 2, 3, 3, NA), b=c(4L, 2L, 0L, 3L, 1L)))
21053+ test(2306.02, sort_by(DT1, ~I(a + b)), data.table(a=c(3, 2, 1, 3, NA), b=c(0L, 2L, 4L, 3L, 1L)))
21054+ test(2306.03, sort_by(DT2, ~a), data.table(a=c("B", "a", "c")))
21055+
21056+ # sort_by.data.table: list columns.
21057+ # NOTE 1: .formula2varlist works well with list columns.
21058+ # NOTE 2: 4 elem in DT of 3 row because forderv takes a list column as a DT.
21059+ test(2306.04, sort_by(DT3, ~b), DT3[order(b)]) # should be consistent.
21060+
21061+ # sort_by.data.table: additional C-locale sorting
21062+ test(2306.10, DT2[, sort_by(.SD, a)], data.table(a=c("B", "a", "c")))
21063+ test(2306.11, DT2[, sort_by(.SD, ~a)], data.table(a=c("B", "a", "c")))
21064+
21065+ # sort_by.data.table: various working interfaces
21066+ test(2306.20, sort_by(DT1, list(DT1$a, DT1$b)), data.table(a=c(1, 2, 3, 3, NA), b=c(4L, 2L, 0L, 3L, 1L)))
21067+ test(2306.21, sort_by(DT1, DT1[, .(a, b)]), data.table(a=c(1, 2, 3, 3, NA), b=c(4L, 2L, 0L, 3L, 1L)))
21068+ test(2306.22, DT1[, sort_by(.SD, .(a, b))], data.table(a=c(1, 2, 3, 3, NA), b=c(4L, 2L, 0L, 3L, 1L)))
21069+ test(2306.23, DT1[, sort_by(.SD, ~a + b)], data.table(a=c(1, 2, 3, 3, NA), b=c(4L, 2L, 0L, 3L, 1L)))
21070+ test(2306.24, DT1[, sort_by(.SD, ~.(a, b))], data.table(a=c(1, 2, 3, 3, NA), b=c(4L, 2L, 0L, 3L, 1L)))
21071+ }
0 commit comments