data.table терпит неудачу, когда это наследуемый класс - PullRequest
2 голосов
/ 09 июля 2019

У меня возникли трудности с использованием структуры наследования с data.table.Когда я применяю новый подкласс к объекту data.table, объект не может вернуться к классу data.table при вызове для выполнения операций data.table.Вот пример:

library('data.table')

dat <- data.table(x = 1:10, y = LETTERS[1:10])
dat <- structure(dat, class = c('new_class', 'data.table'))

dat[, .(x)]
dat[, z:= 5 * x]

Каждая из двух операций data.table, приведенных выше, возвращает следующие сообщения об ошибках:

Error in setnames(x, value) : x is not a data.table or data.frame
Error in setnames(x, value) : x is not a data.table or data.frame
In addition: Warning message:
In `[.data.table`(dat, , `:=`(z, 5 * x)) :
  Invalid .internal.selfref detected and fixed by taking a (shallow) copy of the data.table so that := can add this new column by reference. At an earlier point, this data.table has been copied by R (or was created manually using structure() or similar). Avoid names<- and attr<- which in R currently (and oddly) may copy the whole data.table. Use set* syntax instead to avoid copying: ?set, ?setnames and ?setattr. If this message doesn't help, please report your use case to the data.table issue tracker so the root cause can be fixed or this message improved.

Кажется, что это не относится к классу data.tableвыполнить методы . и :=.Почему это?

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...