Just to clear some things for myself, I would like to better understand when copies are made, and when they are not in data.table. Since this question points to Understanding, when data.table is a reference to (vs copy of) another data.table , if you just run the following, then you end up to change the original:
library(data.table)
DT <- data.table(a=c(1,2), b=c(11,12))
print(DT)
newDT <- DT
newDT[1, a := 100]
print(DT)
However, if you do this (for example), you will end up changing the new version:
DT = data.table(a=1:10)
DT
a
1: 1
2: 2
3: 3
4: 4
5: 5
6: 6
7: 7
8: 8
9: 9
10: 10
newDT = DT[a<11]
newDT
a
1: 1
2: 2
3: 3
4: 4
5: 5
6: 6
7: 7
8: 8
9: 9
10: 10
newDT[1:5,a:=0L]
newDT
a
1: 0
2: 0
3: 0
4: 0
5: 0
6: 6
7: 7
8: 8
9: 9
10: 10
DT
a
1: 1
2: 2
3: 3
4: 4
5: 5
6: 6
7: 7
8: 8
9: 9
10: 10
As I understand it, the reason is that this is because when you execute the statement i, it data.tablereturns the whole new table, and not a link to the memory occupied by the selection elements of the old one data.table. Is this correct and true?
EDIT: , i not j ( )