2

この状況があると想像してみましょう:

  1. 100MB を超える .RData ファイルがたくさんあります (何でも構いませんが、大きいです)。
  2. すべての.RDataファイルには、「Dataset_of_interest」と呼ばれるデータセットがあり、それらはすべて、作成したい1つの大きなデータセットの一部です。

だから、私が興味を持っているこのデータセットだけをメモリにロードすることは可能ですが、.RData ファイル全体をロードすることはできないのでしょうか?

各「Dataset_of_interest」をループでロードし、1 つの大きなファイルにマージしてから、1 つのファイルに保存したいと思います。

編集:私はWindows 7で作業しています。

4

1 に答える 1

3

これは可能であると主張しますが、いくつかの並列処理機能が必要になります。各ワーカーは .RData ファイルをロードし、目的のオブジェクトを出力します。結果をマージすることは、おそらく非常に簡単です。

構造がわからないため、データのコードを提供することはできませんが、以下のチャンクコードの行に沿って何かを行います. 私は Windows を使用しているため、ワークフローが異なる場合があることに注意してください。コンピュータのメモリが不足してはいけません。また、複数のコアを使用するインターフェイスは Snowfall だけではありません。

# load library snowfall and set up working directory
# to where the RData files are
library(snowfall)
working.dir <- "/path/to/dir/with/files"
setwd(working.dir)

# initiate (redneck jargon: and then she ate) workers and export
# working directory. Working directory could be hard coded into
# the function, rendering this step moot
sfInit(parallel = TRUE, cpus = 4, type = "SOCK")
sfExport(list = c("working.dir")) # you need to export all variables but x

# read filenames and step through each, returning only the
# desired object
lofs <- list.files(pattern = ".RData")
inres <- sfSapply(x = lofs, fun = function(x, wd = working.dir) {
    setwd(wd)
    load(x)
    return(Dataset_of_interest)
  }, simplify = FALSE)
sfStop()

# you could post-process the data by rbinding, cbinding, cing...
result <- do.call("rbind", inres)
于 2012-08-07T07:19:52.803 に答える