Dear all, I do not completely understand following behaviour :> con <- file("test.txt") > isOpen(con)[1] FALSE> open(con) > isOpen(con)[1] TRUE> close(con) > isOpen(con)Error in isOpen(con) : invalid connection> str(con)Classes 'file', 'connection' atomic [1:1] 3 ..- attr(*, "conn_id")=<externalptr> Why do I get an error, indicating an invalid connection, after I closed a connection? Is this to be expected? Cheers Joris -- Joris Meys Statistical consultant Ghent University Faculty of Bioscience Engineering Department of Applied mathematics, biometrics and process control tel : +32 9 264 59 87 Joris.Meys at Ugent.be ------------------------------- Disclaimer : http://helpdesk.ugent.be/e-maildisclaimer.php
On 08/04/2011 10:56 AM, Joris Meys wrote:> Dear all, > > I do not completely understand following behaviour : > > > con<- file("test.txt") > > isOpen(con) > [1] FALSE > > open(con) > > isOpen(con) > [1] TRUE > > close(con) > > isOpen(con) > Error in isOpen(con) : invalid connection > > str(con) > Classes 'file', 'connection' atomic [1:1] 3 > ..- attr(*, "conn_id")=<externalptr> > > Why do I get an error, indicating an invalid connection, after I > closed a connection? Is this to be expected?Quoting ?close: " ?close? closes and destroys a connection. " In the current implementation, connections are a finite resource, and you need to be able to get rid of them when you are done. close(con) is the way to do that. If you want to re-open it, you need to remember the filename (or extract it before calling close()), and issue another call to file(). Duncan Murdoch
Maybe Matching Threads
- PATCH: Asserting that 'connection' used has not changed + R_GetConnection2()
- Package snow: is there any way to check if a cluster is "acticve"
- stats::line() does not produce correct Tukey line when n mod 6 is 2 or 3
- `[` not recognized as a primitive in certain cases.
- stats::line() does not produce correct Tukey line when n mod 6 is 2 or 3