Problem:
I wish to create a Reference Class that extends a data.table
.
The motivation being
- Want a
data.table
with custom methods and mutable fields - Still want all existing syntax (such as indexing, subset, merge etc) to work as expected
Problem is I have so far failed.
Attempts:
I tried:
MyDataTable <- setRefClass("MyDataTable",
methods = list(
clearCell = function(i, j) { # A trivial custom method - sets a cell to NA
.self[i, (j) := NA]
}
),
contains = "data.table"
)
MyDataTable(a = 1:26, b = letters)$clearCell(1, 1)
But got the error:
Error in envRefSetField(.Object, field, classDef, selfEnv, elements[[field]]) :
‘a’ is not a field in class “MyDataTable”
However, I was expecting something like:
a b
1: NA a
2: 2 b
3: 3 c
4: 4 d
5: 5 e
6: ... etc etc
What's going wrong?