[Rd] RE: [R] File opening error after 1020 files opened
Henrik Bengtsson
hb@maths.lth.se
Sat Mar 1 03:05:04 2003
Maybe open.connection() should also check if the connection is already
open and given an error or at least a warning if it is. Suggested code
update:
open.connection <- function(con, open="r", blocking=TRUE, ...) {
if (!inherits(con, "connection"))
stop("argument is not a connection")
if (isOpen(con)) # NEW
stop("Trying to open a connection that is already open.") # NEW
invisible(.Internal(open(con, open, blocking)))
}
Henrik Bengtsson
> -----Original Message-----
> From: Roger Bivand [mailto:Roger.Bivand@nhh.no]
> Sent: den 1 mars 2003 06:25
> To: ripley@stats.ox.ac.uk
> Cc: Dirk Eddelbuettel; jonathan_li@agilent.com; hb@maths.lth.se
> Subject: Re: [R] File opening error after 1020 files opened
>
>
> On Fri, 28 Feb 2003 ripley@stats.ox.ac.uk wrote:
>
> > Let's take this off R-help.
> >
> > I did a quick check that connections are behaving:
> >
> > for(i in 1:2000) {
> > print(i)
> > zz <- file("foo", "rb")
> > foo <- readLines(zz)
> > close(zz)
> > }
> >
> > for(i in 1:2000) {
> > print(i)
> > zz <- file(tempfile(), "wb")
> > cat("foobar\n", file=zz)
> > close(zz)
> > }
> >
> > work for me, several times in a session in both Windows and
> Linux. I
> > do know that sometimes under Windows file closing fails, but not
> > often.
> >
> > The file-handle limit on RH7.2 seems to 8096, and I used at least
> > 20000 opens.
> >
> > However, read.pnm has
> >
> > con <- file(file, open = "rb")
> > open(con, open = "rb")
> > ...
> > close(con)
>
> Yes, of course. Revision (pixmap_0.3-2.tar.gz) on incoming,
> should be on
> CRAN before long. If needed, I can attach it. Runs 10000
> read.pnm() now
> without difficulty. I can't recall why I once thought file()
> just set a
> handle and open() actually opened it, wrong assumptions can
> survive for
> years!
>
> Thanks,
>
> Roger
>
> >
> > which opens the connection *twice* and that's creating two file
> > handles and only closing one. See ?file.
> >
> > Brian
[SNIP]