1

xtsを使用していて、ループで100〜1000個のファイルをロードしています。各ファイルは50kから300k行です。Windows764ビットで最新バージョンのR2.15.1を使用しています。Rバージョン2.14.XのUbuntuLinuxでも同じ問題が発生します。

以下のコードは定期的にRをクラッシュさせます:

library(xts)
N <- 1e6
for(i in 1:1000) {
  allTimes <- Sys.time()-N:1
  x <- NULL
  x <- xts(,allTimes)
  sampTimes <- allTimes[seq(1,length(allTimes),by=2)]
  y <- merge(xts(seq_along(sampTimes), sampTimes), allTimes)
  y <- na.locf(y)
  y <- to.period(y, 'seconds', 10)
  index(y) <- index(to.period(x, 'seconds', 10))
}
4

1 に答える 1

4

これはR-develで答えられました。問題はto.period、ゼロ幅のxtsオブジェクトを呼び出すと、ランダムなメモリ位置のOHLCデータが返されることでした。例えば:

library(xts)
x <- xts(,Sys.time()-10:1)
y <- to.period(x)
y
#                           x.Open       x.High         x.Low       x.Close
# 2012-07-23 15:47:30 4.25426e-314 2.36246e-300 1.428936e-316 1.428936e-316

「データなし」を集約しても意味がないため、to.period幅/長さがゼロのオブジェクトで実行するとエラーが発生するようにパッチを適用しました(R-Forgeのリビジョン690)。

幅がゼロのオブジェクトで実行する代わりに、to.periodオブジェクトでいっぱいの一時的なxtsオブジェクトを作成して実行to.periodします。これは、現在CRANにあるxtsで機能します。

library(xts)
N <- 1e6
for(i in 1:100) {
  allTimes <- Sys.time()-N:1
  x <- NULL
  x <- xts(,allTimes)
  sampTimes <- allTimes[seq(1,length(allTimes),by=2)]
  y <- merge(xts(seq_along(sampTimes), sampTimes), allTimes)
  y <- na.locf(y)
  y <- to.period(y, 'seconds', 10)
  tmp <- xts(rep(1,length(allTimes)), allTimes)
  index(y) <- index(to.period(tmp, 'seconds', 10))
}
于 2012-07-23T20:47:35.033 に答える