I see your thought. We refused to use with=TRUE|FALSE in combination with := . Since it is implicitly clear whether with=TRUE refers to the left side or to the right side of := . Instead, it is now preferable to wrap the LHS := brackets.
DT[, x.sum:=cumsum(x)]
As Justin mentioned, most of the time we assign a new or existing column that we know in advance. In other words, most often the assigned column is not held in a variable. We do it in a way that is convenient. However, data.table is flexible and also allows you to specify the name of the target column.
I believe that a case can be made when it should be:
DT[, "x.sum":=cumsum(x)]
However, since := is an assignment operator and j is evaluated within the scope of DT , it would be difficult for me if DT[, x.sum:=cumsum(x)] did not x.sum column.
Explicit parentheses, i.e. (target):= , imply some kind of evaluation, so the syntax is more clear. In my opinion, anyway. Of course you can call paste0 , etc. Directly on the left side := also unnecessarily with=FALSE ; eg.
DT[, paste0("SUM.",colNames) := lapply(.SD, ...), by=...]
In short, I never use with when I use := .
source share