[R] Getting rid of extra connections?

Don MacQueen macq at llnl.gov
Fri Oct 4 23:36:53 CEST 2002

Thank you Peter,

For anyone who is interested, these two examples illustrate nicely:

## example 1
for (i in 1:50) {foo <- pipe('date') ; rm(foo) ; cat(i,' ')}

## example 2
for (i in 1:50) {foo <- pipe('date') ; close(foo) ; cat(i,' ')}

I would have sworn I had tried putting that close() in there, but 
evidently I didn't. Also, I was looking at ?connections, but missed 
?showConnections. Oops.

I did figure out that I was wrong about split.screen being the cause. 
I'm actually monitoring several data files that have new data 
appended once per minute, and my current code uses pipe() like yours. 
Down the road I'm hoping to use a socket connection.

>  version
platform sparc-sun-solaris2.7
arch     sparc              
os       solaris2.7         
system   sparc, solaris2.7  
major    1                  
minor    5.1                
year     2002               
month    06                 
day      17
language R                  


At 11:00 PM +0200 10/4/02, Peter Dalgaard BSA wrote:
>Don MacQueen <macq at llnl.gov> writes:
>>  I'm trying to figure out how to get out of this situation:
>>  >  source('monit.r')
>>  Error in file(file, "r") : All connections are in use
>>  >  showConnections()
>>        description class mode text isopen can read can write
>>  >  help.search('connection')
>>  Error in file(file, "r") : All connections are in use
>>  >  q()
>>  Save workspace image? [y/n/c]: y
>>  Error in file(file, "wb") : All connections are in use
>>  As best as I can tell, I got a bunch of extra connections by
>>  experimenting with the split.scree() and layout() functions. But I
>>  can't, so far, find a way to remove or close them. When I use ls() to
>>  see a list of objects, they all look like things I explicitly created,
>>  i.e., vectors, lists, functions, etc., and not like connection
>>  objects. I can't find any connection object to close with the close()
>>  function. I have closed all graphics devices with dev.off().
>>  I suppose I can quit without saving, and then restart R to get out of
>>  this mess, but I'd like to find a clean way out. Suggestions?
>Happened to me recently. (With a function designed to monitor my sales
>rank at Amazon if you must know...) showConnections(all=T) indicates
>what is up, and closeAllConnections() is the immediate way out. To
>avoid getting into the pickle in the first place, you need to use code
>    z <- scan(c<-pipe("grep -v CEST ~/sales.log"))
>    close(c)
>The last bit looks like a clear bug. Surely, we could
>closeAllConnections() before trying to save the workspace?
>    O__  ---- Peter Dalgaard             Blegdamsvej 3 
>   c/ /'_ --- Dept. of Biostatistics     2200 Cph. N  
>  (*) \(*) -- University of Copenhagen   Denmark      Ph: (+45) 35327918
>~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk)             FAX: (+45) 35327907

Don MacQueen
Environmental Protection Department
Lawrence Livermore National Laboratory
Livermore, CA, USA
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch

More information about the R-help mailing list