R-alpha: EOF in read.table() and count.fields()

Kurt Hornik (Kurt.Hornik@ci.tuwien.ac.at)
Mon, 25 Nov 1996 08:16:11 +0100


Date: Mon, 25 Nov 1996 08:16:11 +0100
Message-Id: <199611250716.IAA14936@aragorn.ci.tuwien.ac.at>
From: Kurt Hornik <Kurt.Hornik@ci.tuwien.ac.at>
To: Douglas Bates <bates@stat.wisc.edu>
Subject: R-alpha: EOF in read.table() and count.fields()
In-Reply-To: <m0vQwyD-000hhvC@franz.stat.wisc.edu>

>>>>> On Fri, 22 Nov 1996 08:52:45 -0600 (CST),
>>>>> Douglas Bates <bates@stat.wisc.edu> said:

> I created a file in emacs and forgot to add a "\n" on the last
> record.  read.table() didn't like that.  Even more surprising was the
> result of count.fields() applied to it.  I'll try to look at it later
> to decide what count.fields was counting in the last case.
>> hw <- read.table("/tmp/ttt")
>  Error: all rows must have the same length
>> count.fields("/tmp/ttt")
>   [1]          7          7          7          7          7          7
>   [7]          7          7          7          7          7          7
>  [13]          7          7          7          7          7          7
>  [19]          7          7          7          7          7          7
>  [25]          7          7          7          7          7          7
>  [31]          7          7 1077306172

I thought you had basically the same Debian GNU/Linux system as me
(1.1.x, kernel is 2.0.x, libc 5.2.18)?

I run into the same problems when using Emacs, but for me count.fields()
never returns.

I played a little with the code for do_countfields() in src/main/scan.c.
The problem seems to be that the EOF test in the for(;;) loop is never
reached.  Replacing

	for(;;) {
		c = scanchar();
		if(c == EOF)  {

by

	for(;;) {
		if((c = fgetc(fp)) == EOF)  {

seems to fix that, but

	for(;;) {
		if((c = scanchar()) == EOF)  {

does not (although this should do the same, right?)

Hmm.  Perhaps someone has an idea about what is going on.  Btw, the
subsequent 

			if(nfields != 0) {
				INTEGER(ans)[nlines] = nfields;
				nlines++;
			}

should rather be

			if(nfields != 0) {
				INTEGER(ans)[nlines] = nfields;
			}
(I think).

-k
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
r-testers mailing list -- For info or help, send "info" or "help",
To [un]subscribe, send "[un]subscribe"
(in the "body", not the subject !)  To: r-testers-request@stat.math.ethz.ch
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-