[Rd] warning upon automatic close of connection

From: Gabor Grothendieck <ggrothendieck_at_gmail.com>
Date: Wed, 12 Sep 2007 08:21:06 -0400


I noticed that under R 2.6.0 there is a warning about closing the connection in the code from this post:
https://stat.ethz.ch/pipermail/r-help/2007-September/140601.html

which is evidently related to the following from the NEWS file:

    o	Connections will be closed if there is no R object referring to
	them.  A warning is issued if this is done, either at garbage
	collection or if all the connection slots are in use.

If we use read.table directly it still happens:

# use Lines and Lines2 from cited post
library(zoo)
DF1 <- read.table(textConnection(Lines), header = TRUE) DF2 <- read.table(textConnection(Lines2), header = TRUE) z1 <- zoo(as.matrix(DF1[-1]), as.Date(DF1[,1], "%d/%m/%Y")) z2 <- zoo(as.matrix(DF2[-1]), as.Date(DF2[,1], "%d/%m/%Y")) both <- merge(z1, z2)
plot(na.approx(both))

> R.version.string # Vista
[1] "R version 2.6.0 alpha (2007-09-06 r42791)"

Is this annoying warning really necessary? I assume we can get rid of it by explicitly naming and closing the connections but surely there should be a way to avoid the warning without going to those lengths.

I would have thought that read.table opens the connection then it would close it itself so no warning would need to be generated.

> # use Lines and Lines2 from cited post
> library(zoo)
> DF1 <- read.table(textConnection(Lines), header = TRUE)
> DF2 <- read.table(textConnection(Lines2), header = TRUE)
> z1 <- zoo(as.matrix(DF1[-1]), as.Date(DF1[,1], "%d/%m/%Y"))
> z2 <- zoo(as.matrix(DF2[-1]), as.Date(DF2[,1], "%d/%m/%Y"))
> both <- merge(z1, z2)
> plot(na.approx(both))

Warning messages:
1: closing unused connection 4 (Lines2)
2: closing unused connection 3 (Lines)



R-devel_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel Received on Wed 12 Sep 2007 - 12:24:05 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Wed 12 Sep 2007 - 16:40:39 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-devel. Please read the posting guide before posting to the list.