Skip to content

let j = c(prefix = lapply(.SD, f)) work when optimized #2311

@franknarf1

Description

@franknarf1

With

library(data.table)
DT = data.table(a = 1, b = 2)

DT[, c(sq = lapply(.SD, "^", 2))]
#    sq.a sq.b
# 1:    1    4
DT[, c(sq = lapply(.SD, "^", 2)), by=1]
#    NA a b
# 1:  1 1 4

The prefix "sq" disappears in the latter case. Judging by the verbose=TRUE output, this is due to "lapply optimization" which takes names strictly from .SD.

(Sorry if I filed this issue already before this; I'm sure it's bothered me for a while. A recent case: I wanted to write IDDT = dat[order(-t), c(max = .SD[1]), by=ID], but no dice.)

Related: #1604

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions