2

ディスクからロードされたばかりの:=data.table の関数から呼び出された場合、 は機能しないようです。最初に何かをすることdata.tableは役に立ちます。これは のバグですかdata.table、それとも何か不足していますか (つまり、data.table と の悪用:=)?

サンプルコード:

# Generate a dummy data.table and save to disk
library(data.table)
DT <- data.table(a=c(1:10), b=c(1:10))
save(DT, file="c:/temp/DT.rData")

# Now define and use a function which is supposed to change the data.table
> library(data.table)
> 
> myfn <- function(data="DT") {
+ DD <- get(x=data, inherits=TRUE, mode="list")
+ DD[, c:="a", verbose=TRUE] }
> load(file="c:/temp/DT.rData")
> myfn(data="DT")
.internal.selfref ptr is NULL. This is expected and normal for a data.table loaded from disk. If not, please report to datatable-help.
Growing vector of column pointers from truelength  0  to  102 . A shallow copy has been taken, see ?alloc.col. Only a potential issue if two variables point to the same data (we can't yet detect that well) and if not you can safely ignore this. To avoid this message you could alloc.col() first, deep copy first using copy(), wrap with suppressWarnings() or increase the 'datatable.alloccol' option.
.internal.selfref ptr is NULL. This is expected and normal for a data.table loaded from disk. If not, please report to datatable-help.
Detected that j uses these columns: <none> 
Assigning to all 10 rows
     a  b c
 1:  1  1 a
 2:  2  2 a
 3:  3  3 a
 4:  4  4 a
 5:  5  5 a
 6:  6  6 a
 7:  7  7 a
 8:  8  8 a
 9:  9  9 a
10: 10 10 a
# This seems to be the correct (desired) result, but does not "stick":
> DT
     a  b
 1:  1  1
 2:  2  2
 3:  3  3
 4:  4  4
 5:  5  5
 6:  6  6
 7:  7  7
 8:  8  8
 9:  9  9
10: 10 10

余分な行を追加して同じコードを実行すると、DT <- copy(DT)意図したとおりに DT が変更されます。

> myfn <- function(data="DT") {
+ DD <- get(x=data, inherits=TRUE, mode="list")
+ DD[, c:="a"] }
> 
> load(file="c:/temp/DT.rData")
> DT <- copy(DT)
> myfn(data="DT")
     a  b c
 1:  1  1 a
 2:  2  2 a
 3:  3  3 a
 4:  4  4 a
 5:  5  5 a
 6:  6  6 a
 7:  7  7 a
 8:  8  8 a
 9:  9  9 a
10: 10 10 a
> DT
     a  b c
 1:  1  1 a
 2:  2  2 a
 3:  3  3 a
 4:  4  4 a
 5:  5  5 a
 6:  6  6 a
 7:  7  7 a
 8:  8  8 a
 9:  9  9 a
10: 10 10 a

上記の使用方法に根本的な問題はあり:=ますか? myfn()を使用して の別の定義を試みましたset()が、結果は同じでした。ありがとう。

> sessionInfo()
R version 3.0.1 (2013-05-16)
Platform: x86_64-w64-mingw32/x64 (64-bit)

locale:
[1] LC_COLLATE=English_United States.1252  LC_CTYPE=English_United States.1252   
[3] LC_MONETARY=English_United States.1252 LC_NUMERIC=C                          
[5] LC_TIME=English_United States.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] data.table_1.8.9
4

0 に答える 0