[R] Too many open files

Markus Loecher markus at insightfromdata.com
Thu Dec 27 16:56:32 CET 2007


Dear all,
Did this problem that was posted in 2006 (see below) ever got fully resolved
?
I am encountering the exact same issue
; I have executed get.hist.quote() in a loop and now R not only refuses to
establish any further connections to yahoo, but, worse, it will not open any
files either. For example, I cannot even save my current workspace for that
reason.
I tried 
  closeAllConnections()
As well as 
  showConnections()
But I do not see any open connections.
Also, does get.hist.quote() not close its connection internally once it is
done ?

Any help would be immensely useful as I am quite stuck.
Thanks!

Markus



Re: [R] Too many open files

    * This message: [ Message body ] [ More options ]
    * Related messages: [ Next message ] [ Previous message ] [ In reply to
] [ [R] error reports ] [ Next in thread ]

From: Seth Falcon <sfalcon_at_fhcrc.org>
Date: Sat 27 May 2006 - 09:21:36 EST

"Omar Lakkis" <uofiowa at gmail.com> writes:

> This may be more of an OS question ...
> I have this call
>
> r = get.hist.quote(symbol, start= format(start, "%Y-%m-%d"), end=
> format(end, "%Y-%m-%d"))
> which does a url request
>
> in a loop and my program runs out of file handlers after few hundred
> rotations. The error message is: 'Too many open files'. Other than
> increasing the file handlers assigned to my process, is there a way to
> cleanly release and reuse these connections?

Inside your loop you need to close the connection object created by url().

for (i in 1:500) {

    con <- url(urls[i])
    ## ... stuff here ...
    close(con)
}

R only allows you to have a fixed number of open connections at one time,
and they do not get closed automatically when they go out of scope. These
commands may help make clear how things work...

> showConnections()

     description class mode text isopen can read can write
> f = url("http://www.r-project.org", open="r")
> showConnections()

From: Gabor Grothendieck <ggrothendieck_at_gmail.com>
Date: Sat 27 May 2006 - 09:47:20 EST

Try closeAllConnections()



More information about the R-help mailing list