Reputation: 834
I have an user defined function:
xml2csv = function(inputFile,outputFile) {
X <- read.table(inputFile, header = FALSE, fill = TRUE,sep=" ")
#step1: seperate cell by one or more space
Y <- concat.split.multiple(X, as.vector(colnames(X)), "")
#step2: seperate cell by ":"
Z <- concat.split.multiple(Y, as.vector(colnames(Y))[-c(1:2)], ":")
#delete repeat rows
U=Z[!Z[,1] == "__REPEAT__", ]
#convert factor column as character
V <- data.frame(lapply(U, as.character), stringsAsFactors=FALSE)
W = V
W[is.na(W)] = 0
write.csv(W, outputFile, quote = F, row.names = F)
}
It works perfectly fine for small inputFile; when the input file is big (>2000kb), the following error appears:
Error in textConnection(text, encoding = "UTF-8") : all connections are in use
Any suggestions?
Upvotes: 1
Views: 2335
Reputation: 4094
It's hard to tell what's going on exactly (your error is not reproducible!), but my money is on it's a bug/limitation of concat.split.multiple
when you have too many columns in X
, since
concat.split
on each of the columns in lapply
, textConnection
internally, Upvotes: 3