0

私は少し R 初心者ですが、acast、ff、ffbase パッケージを使用して、かなり大きな R オブジェクト (5 ミリ行 x ~17k 列) を作成しようとしています - SQLServer データセットが取り込まれ、小さなデータフレーム チャンクにキャストされて溶解されます (もちろん、1 つの単純な溶解と dcast でこのオブジェクトを作成することはできません)。すべてのチャンクに同じ列があります。ffdfappend にたどり着くと、R がクラッシュします。Windows がクラッシュします (R for Windows GUI フロントエンドが機能しなくなりました)。私の主な質問は、この時点で、ffdfappend を正しく使用していますか?

Windows Server 2008 - 64 ビット R 2.15.3 - 64 ビット

私の「チャンクアップ」コード:

library(RODBC);
library(reshape2);
library(ff);
library(ffbase);

db <- odbcConnect(foo);

#agg function used in the acast
iSequence <- function(x){
 if(is.na(min(x))) {
  return('N');
 } else {
  if(min(x) == 1) {
   return('P');
  } else {
   return('S');
  }
 }
}

#pull in data from SS
data.raw <- sqlQuery(db,"
SELECT 
key
,type
,val
FROM table
WHERE val IS NOT NULL
",stringsAsFactors=FALSE);

#melt
data.melt <- melt(data.raw,id=c("key","type"),measure="val");

#get list of unique first 4 digits of key - good enough granularity for chunk
data.char <- unique(substr(data.melt$key,1,4));

#create list where the chunked casts will reside
data.df.list <- vector("list",length(data.char));

#get list of unique column names
data.type.unique <- unique(data.melt$type);

#chunk counter
chunk.count <- 1;

#cast by chunk 
for(i in data.char) {
 print(paste(chunk.count, '/', length(data.char)));
 tempcast <- acast(data.melt[substr(data.melt$key,1,4)==i,],key~type,fun.aggregate=iSequence);
 #create list item with all N
 templist <- matrix(
  data="N",
  nrow=nrow(tempcast),
  ncol=length(data.type.unique),
  dimnames=list(rownames(tempcast),data.type.unique)
 );
 #replace columns that are in data.type.unique but not in tempcast
 templist[,which(data.type.unique %in% colnames(tempcast))] <- tempcast;
 #put into final cast list
 data.df.list[[i]] <- as.data.frame(templist);
 rm(tempcast);
 rm(templist);
 gc();
 chunk.count <- chunk.count + 1;
}

これで、すべてのチャンクを取得できました (データは問題なく、有効に見えます)。2 つのチャンクで ffdfappend をテストすると (これらは値の動作です)、R がクラッシュします。

#this works 
#unsort is in there because I get an error saying this is sorted otherwise
t1 <- NULL;
t1 <- unsort(ffdfappend(t1,data.df.list[["1174"]]));
t2 <- NULL;
t2 <- unsort(ffdfappend(t2,data.df.list[["1175"]]));

#this crashes R
t1 <- ffdfappend(t2,t1);

ffdfappend を正しく使用していますか? ありがとう!

4

0 に答える 0