Paul.j
Paul.j

Reputation: 834

R: Error in textConnection: all connections are in use

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

Answers (1)

Victor K.
Victor K.

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

  • it calls concat.split on each of the columns in lapply,
  • which uses textConnection internally,
  • which creates a temporary file,
  • which uses a file handler,
  • which is a limited resource in most operating systems :).

Upvotes: 3

Related Questions