Unqualified data tables, passed as function arguments, are modifiable without copy on modify:
dt<-data.table(RowId=c('a','b','c','d'),x=0:3)
f<-function(adt){adt[,x:=4]}
f(dt)
dt
# RowId x
#1: a 4
#2: b 4
#3: c 4
#4: d 4
I'd like to preserve this behavior on a restricted set of rows as in:
f(dt[x>1])
dt
# RowId x
#1: a 0
#2: b 1
#3: c 4
#4: d 4
rather than having to embed the restriction in the function or passing the restriction as an argument to be evaled within the function.
Is there a way to accomplish this?
If not, what is the most parsimonious way of replacing the rows of dt
corresponding to those in the copy returned from the function?