Skip to content

Commit 2ea0174

Browse files
committed
add coverage and edge cases
1 parent 54af162 commit 2ea0174

2 files changed

Lines changed: 10 additions & 1 deletion

File tree

R/data.table.R

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,10 @@ replace_dot_alias = function(e) {
271271
# Case 2b: list(...)
272272
else if (this[[1L]] == "list") {
273273
# also handle c(lapply(.SD, sum), list()) - silly, yes, but can happen
274-
if (length(this) == 1L) next
274+
if (length(this) == 1L) {
275+
jsubl[[i_]] = list() # empty list gets dropped by unlist later
276+
next
277+
}
275278
jl__ = as.list(jsubl[[i_]])[-1L] # just keep the '.' from list(.)
276279
# Fix for #2311, prepend named list arguments of c() to that list's names. See tests 2283.*
277280
jl__names = names(jl__) %||% rep("", length(jl__))
@@ -3383,6 +3386,7 @@ is_constantish = function(q, check_singleton=FALSE) {
33833386
# run GForce for simple f(x) calls and f(x, na.rm = TRUE)-like calls where x is a column of .SD
33843387
.get_gcall = function(q) {
33853388
if (!is.call(q)) return(NULL)
3389+
if (length(q) < 2L) return(NULL) # e.g. list()
33863390
# is.symbol() is for #1369, #1974 and #2949
33873391
if (!is.symbol(q[[2L]]) && !is.call(q[[2L]])) return(NULL)
33883392
if (is.call(q[[2L]]) && !.is_type_conversion(q[[2L]])) return(NULL)

inst/tests/tests.Rraw

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21475,3 +21475,8 @@ test(2361.44, optimize=0:2, dt[, sum(a) + as.numeric("5"), by=b, verbose=TRUE],
2147521475
test(2361.45, optimize=0:2, dt[, sum(a[a > 2]), by=b, verbose=TRUE], output="GForce FALSE")
2147621476
dt = data.table(a=1:4, b=1:2, c=2:5)
2147721477
test(2361.46, optimize=0:2, dt[, .(sum(a) + sum(c)), by=b, verbose=TRUE], output=out)
21478+
# coverage and edge cases for lapply(.SD, ...)
21479+
dt = data.table(a=1:4, b=1:2)
21480+
test(2361.51, optimize=0:2, dt[, c(list()), b, verbose=TRUE], data.table(b=integer(0L)), output="GForce FALSE")
21481+
test(2361.52, optimize=0:2, dt[, c(lapply(.SD, sum), list()), b, verbose=TRUE], output=out)
21482+
test(2361.53, optimize=0:2, dt[, list(lapply(.SD, sum), list()), b, verbose=TRUE], output="GForce FALSE")

0 commit comments

Comments
 (0)