I do not know R, but I read the definition of onexeit , add = true , so that the first expression is evaluated in addition to any previously saved single protrusions, and add = false overwrites the previous one.
So, looking back, I found this on jhsph.edu :
It seems like basically making sure tmp also closed, and file on exit
readData2 <- function(file, ...) { file <- file(file, "r") on.exit(close(file)) tmp <- tempfile() tmpcon <- file(tmp, "w") on.exit(close(tmpcon), add = TRUE) incomment <- FALSE while(length(line <- readLines(file, 1)) > 0) { . . . ommited in SO example . . . } close(tmpcon) close(file) on.exit() read.csv(tmp, ...) }
source share