[R] data import problem

Thomas Lumley tlumley at u.washington.edu
Wed Mar 8 15:55:50 CET 2006


On Wed, 8 Mar 2006, Arne.Muller at sanofi-aventis.com wrote:
>
> I thought I coudl simply use something line this:
>
> con <- file("test2.txt");
> do {
>    e <- read.table(con, nlines = 1);
>    if ( length(e) == 2 ) {
> 	d <- read.table(con, nrows = e[1,2]);
> 	#process data frame d
>    }
> } while (length(e) == 2);
>
> The problem is that read.table closes the connection object, I assumed 
> that it would not close the connection, and instead contines where it 
> last stopped.

I think the problem is just that you didn't open the connection before 
passing it to read.table.

?file says "By default the connection is not opened"
and
?read.table says
           Alternatively, 'file' can be a 'connection', which will be
           opened if necessary, and if so closed at the end of the
           function call.



 	-thomas




More information about the R-help mailing list