diff --git a/R/data.table.R b/R/data.table.R index d72e75d98..73255bc1e 100644 --- a/R/data.table.R +++ b/R/data.table.R @@ -1383,10 +1383,11 @@ chmatch2 <- function(x, table, nomatch=NA_integer_) { nomeanopt=FALSE # to be set by .optmean() using <<- inside it oldjsub = jsub if (jsub[[1L]]=="list") { - for (ii in seq_along(jsub)[-1L]) + for (ii in seq_along(jsub)[-1L]) { if (dotN(jsub[[ii]])) next; # For #5760 if (is.call(jsub[[ii]]) && jsub[[ii]][[1L]]=="mean") jsub[[ii]] = .optmean(jsub[[ii]]) + } } else if (jsub[[1L]]=="mean") { jsub = .optmean(jsub) } diff --git a/inst/tests/tests.Rraw b/inst/tests/tests.Rraw index 0f2c17029..8f48831bc 100644 --- a/inst/tests/tests.Rraw +++ b/inst/tests/tests.Rraw @@ -4907,6 +4907,9 @@ test(1362.13, DT[, head(.SD, 1), by=x, verbose=TRUE], test(1362.14, names(DT[, c(list(.I, mean(y)), lapply(.SD, sum)), by=x]), c("x", "I", "V2", "y", "z")) # and if a name is given, it's retained test(1362.15, names(DT[, c(list(bla=.I, mean(y)), lapply(.SD, sum)), by=x]), c("x", "bla", "V2", "y", "z")) +# Add test to ensure that mean() gets replaced with fastmean when GForce won't be used. +test(1362.16, DT[, c(list(.I, mean(y)), lapply(.SD, mean)), by=x, verbose=TRUE], + output="Old mean optimization changed j from 'list(.I, mean(y), mean(y), mean(z))' to 'list(.I, .External(Cfastmean, y, FALSE), .External(Cfastmean, y, FALSE), .External(Cfastmean, z, FALSE))'") # setDT(DT), when input is already a data.table checks if selfrefok and if not, does alloc.col again. DT = list(data.frame(x=1:5, y=6:10))