When I run the following code in a loop I get an error after about 125 times saying too many open files... if(inherits(atmpt, "try-error")){ output <- paste(yahooSymbol,"\n",sep="") write(output, file = "data", append = TRUE, sep = "") } else { I've tried various things to close the file after write opens it, and looked through the RBase docs... but I can't find anything that succesfully closes the file. This is obviously trivial... any ideas Nick [[alternative HTML version deleted]]
Try: closeAllConnections() On Mon, Dec 21, 2009 at 3:22 PM, Nick Torenvliet <nick.torenvliet at gmail.com> wrote:> When I run the following code in a loop I get an error after about 125 times > saying too many open files... > > > if(inherits(atmpt, "try-error")){ > ? ? ? ? ? ?output <- paste(yahooSymbol,"\n",sep="") > ? ? ? ? ? ?write(output, file = "data", append = TRUE, sep = "") > } else { > > > I've tried various things to close the file after write opens it, and looked > through the RBase docs... but I can't find anything that succesfully closes > the file. > > This is obviously trivial... any ideas > > Nick > > ? ? ? ?[[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >-- Henrique Dallazuanna Curitiba-Paran?-Brasil 25? 25' 40" S 49? 16' 22" O
Hi Nick, I hope you're being a little disingenuous about how hard you looked.... Typing ?close will pull up the right help page. I think you're having trouble because you don't store the file object in a variable, so there's no convenient way to refer to it when you need to close it (or when you want to write to it...). Do three different steps: 1) open file. 2) write to file. 3) close file; and you should be fine. You also don't need to open the file 125 times: open it before the loop. --Gray On Mon, Dec 21, 2009 at 11:22 AM, Nick Torenvliet <nick.torenvliet at gmail.com> wrote:> When I run the following code in a loop I get an error after about 125 times > saying too many open files... > > > if(inherits(atmpt, "try-error")){ > ? ? ? ? ? ?output <- paste(yahooSymbol,"\n",sep="") > ? ? ? ? ? ?write(output, file = "data", append = TRUE, sep = "") > } else { > > > I've tried various things to close the file after write opens it, and looked > through the RBase docs... but I can't find anything that succesfully closes > the file. > > This is obviously trivial... any ideas > > Nick > > ? ? ? ?[[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >-- Gray Calhoun Assistant Professor of Economics Iowa State University