r - How can I make a method to acces a data.table in a structure? -
suppose have this:
dt <- data.table(x = 1:10, y = 1:2) s <- structure(list(dt = dt), class = 'dt_test')
i want define [ function objects of class dt_test pass on arguments dt. example want able things like
s[, sum(x), = y] s[, z := x + y]
where [ applied dt. how can make happen?
it can done, i'm not sure should done though. defining method [
sends arguments down data.table pretty straight forward:
`[.dt_test` <- function(x, ...){ x[[1]][...] } s[, sum(x), = y]
you have similar generics want supported, example want define [[
.
i rather recommend referring data.table inside list directly, majo suggested in comment question. way it's easier understand whats happening in code else might reading (e.g. future you).
Comments
Post a Comment