From murdoch at stats.uwo.ca  Sun Jan  1 18:26:23 2006
From: murdoch at stats.uwo.ca (Duncan Murdoch)
Date: Sun, 01 Jan 2006 12:26:23 -0500
Subject: [Rd] Enhancement request: anonymous connections
In-Reply-To: <m2ek3xcm32.fsf@fhcrc.org>
References: <m2mzimc9zj.fsf@fhcrc.org> <43B1EE08.4090003@stats.uwo.ca>
	<m2ek3xcm32.fsf@fhcrc.org>
Message-ID: <43B810BF.8080309@stats.uwo.ca>

On 12/28/2005 9:50 AM, Seth Falcon wrote:
> On 27 Dec 2005, murdoch at stats.uwo.ca wrote:
> 
>>This is a bug in load, isn't it?  load() opens the connection but
>>doesn't close it.
> 
> 
> Well, it may be that load needs a small fix, but that doesn't fix
> anonymous connections in general, IMO.

No it doesn't.  However, I've committed the small fix.
> 
> The loop could easily have been:
> 
> for (i in 1:50) {
>     print(load(url(testUrl, open="r")))
> }
> 
> And it doesn't need to be related to url or load:
> 
> cat("a line of text\n", file="another-example.txt")
> z <- NULL
> for (i in 1:50) {
>     z <- c(z, readLines(file("another-example.txt", open="r")))
> }
> 
> Also, connections are "in use" even if they are closed:
> 
> for (i in 1:50) {
>     if (isOpen(file("another-example.txt")))
>         stop("you will not get here")
> }

I think the general problem is that R doesn't have references (or at 
least, they aren't in a final, documented state).  If the garbage 
collector closed a connection, then things would go wrong when there 
were two copies of it:  the second one would be messed up when the first 
was destroyed.  If we had references, then opening a connection could 
create a connection object and a reference to it; the connection object 
would remain as long as there were any references to it, and could be 
destroyed (and automatically closed) after the last reference was gone.

Duncan Murdoch



[Rd] Enhancement request: anonymous connections
Duncan Murdoch