이것은 내가하고 싶은 최소한의 예입니다. data.table을 기반으로 자신 만의 클래스를 만들고 싶습니다. 대부분의 data.table 함수를 내 자신의 클래스 사용자가 사용할 수 있도록하고 싶지만 계산이 필요한만큼 작동하지만 아래 예제와 같이 data.table 구문을 사용하면 파생 클래스의 태그가 삭제됩니다.data.table에서 새 클래스를 파생
는test0.dt <- copy(test.dt)
class(test0.dt)
이 이 이
"deriv"클래스 속성이 삭제됩니다 :
library(data.table)
test.dt <- data.table(a=1:10, b=rep(1,10))
setattr(test.dt, "class", c("deriv", class(test.dt)))
class(test.dt)
는 "deriv"클래스 속성을 유지합니다!
test1.dt <- test.dt[ a>=2 & a<=9 ]
class(test1.dt)
test2.dt <- test.dt[ a %between% c(2,9)]
class(test2.dt)
test3.dt <- test.dt[ 2:9 ]
class(test3.dt)
파생 클래스에 대해 보유하려는 모든 data.table 함수의 특수 버전을 작성하지 않으면이 문제를 해결할 수있는 방법이 있습니까? 클래스 속성을 명시 적으로 복사/복원하는 data.table 함수에 래퍼 만 있으면됩니다.
"예상치 못한"동작처럼 보입니다. 비교를 위해 아래 코드는 "deriv"클래스 속성을 절대로 폐기하지 않습니다.
test.df <- data.frame(a=1:10, b=rep(1,10))
class(test.df) <- c("deriv", class(test.df))
class(test.df)
test0.df <- test.df
class(test0.df)
test1.df <- test[ test.df$a>=2 & test.df$a<=9 , ]
class(test1.df)
test2.df <- test.df[ 2:9, ]
class(test2.df)
이전 버전의'data.table'을 사용하고 있습니다. 'sessionInfo()'를 게시 할 수 있습니까? – Arun
현재 CRAN 버전 1.9.2의 data.table을 사용하고있었습니다. 나는 Github에서 당겨서 현재의 개발 버전 인 1.9.3을 설치하고 구축했다. 문제는 해결되었다. 감사! –
@PedroAphalo 질문에 답변 해 답변으로 표시 할 수 있습니까? – jangorecki