[Rd] warning upon automatic close of connection

Gabor Grothendieck ggrothendieck at gmail.com
Wed Sep 12 14:21:06 CEST 2007


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)



More information about the R-devel mailing list