[R] Why I get this error? Error in close.connection(f) : invalidconnection

William Dunlap wdunlap at tibco.com
Tue Oct 27 23:34:08 CET 2009


> -----Original Message-----
> From: r-help-bounces at r-project.org 
> [mailto:r-help-bounces at r-project.org] On Behalf Of Peng Yu
> Sent: Tuesday, October 27, 2009 3:22 PM
> To: r-help at stat.math.ethz.ch
> Subject: [R] Why I get this error? Error in 
> close.connection(f) : invalidconnection
> 
> I don't understand why I can not close 'f'. This may be very simple,
> but I don't see why. Could somebody let me know?

The short answer is that f is not an open connection.
Use f <- file(..., open="r") if you want to open it
(and then read.csv should not close it).

Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com 
> 
> $ cat gzfile.csv
> "","V1","V2","V3","V4","V5"
> "1",1,5,9,13,17
> "2",2,6,10,14,18
> "3",3,7,11,15,19
> "4",4,8,12,16,20
> $ Rscript gzfile.R
> > f = file("gzfile.csv")
> > A = read.csv(f)
> > A
>   X V1 V2 V3 V4 V5
> 1 1  1  5  9 13 17
> 2 2  2  6 10 14 18
> 3 3  3  7 11 15 19
> 4 4  4  8 12 16 20
> > close(f)
> Error in close.connection(f) : invalid connection
> Calls: close -> close.connection
> Execution halted
> 
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide 
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
> 




More information about the R-help mailing list