1
我嘗試從ReferenceClass的方法返回的data.table
S複製:返回的data.table副本從ReferenceClass方法
dummy <- setRefClass(
"dummy",
fields = list(
dt = "data.table"
),
methods = list(
initialize = function(df){
if(!missing(df)){
dt <<- data.table(df , key = "a")
}
},
getTab = function(ix){
return(copy(dt[ ix, ]))
}
)
)
但是,調用dummy$getTab()
得到我不明白的錯誤:
d <- dummy$new(data.frame(a = 1:10, b = 1:10))
d$getTab(2:5)
Error in if (shallow) assign(field, get(field, envir = selfEnv), envir = vEnv) else { :
argument is not interpretable as logical
In addition: Warning message:
In if (shallow) assign(field, get(field, envir = selfEnv), envir = vEnv) else { :
the condition has length > 1 and only the first element will be used
我不知道,它是什麼意思,它來自哪裏。另外,以下兩個程序沒有任何問題:
copy(d$dt[ 2:5 ])
mycopy <- function(dt, ix) {
return(copy(dt[ ix, ]))
}
mycopy(d$dt, 2:5)
任何幫助表示讚賞。