bugs in scan() (PR#304)
Ray.Brownrigg@mcs.vuw.ac.nz
Ray.Brownrigg@mcs.vuw.ac.nz
Mon, 1 Nov 1999 00:20:56 +0100 (MET)
System: Sun Solaris 2.5.1
There seem to be at least 2 bugs associated with the use of flush=T in
the scan function.
1) If flush=T is used, scan() will only ask for 1 line from standard input.
Repeat by:
> R
R : Copyright 1999, The R Development Core Team
Version 0.65.1 Release (October 07, 1999)
R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type "?license" or "?licence" for distribution details.
R is a collaborative project with many contributors.
Type "?contributors" for a list.
Type "demo()" for some demos, "help()" for on-line help, or
"help.start()" for a HTML browser interface to help.
Type "q()" to quit R.
> scan(what=list(c1=0,c2=0,c3=0), flush=T)
1: 1 2 3 4
Read 1 lines
$c1
[1] 1
$c2
[1] 2
$c3
[1] 3
>
1a) If the 'correct' number of fields are supplied, then two lines are
read, but only 1 is 'registered':
> scan( what=list(c1=0,c2=0,c3=0),flush=T)
1: 1 2 3
1: 4 5 6
Read 1 lines
$c1
[1] 1
$c2
[1] 2
$c3
[1] 3
>
2) When reading from a file, the first line is processed correctly, but
the second and subsequent lines do not have the extraneous data flushed
correctly. Repeat by:
> write(t(matrix(1:15, ncol=5, byrow=T)), "tmp")
> system("cat tmp")
1 2 3 4 5
6 7 8 9 10
11 12 13 14 15
> scan("tmp", what=list(c1=0,c2=0,c3=0), flush=T)
Read 4 lines
$c1
[1] 1 6 10 3
$c2
[1] 2 7 11 14
$c3
[1] 3 8 12 15
Warning message:
line 3 did not have 3 elements
>
Notice that on lines 2 and 3 the first character of the "flushable
data" (after the field separator) does get flushed, but then scanning
continues. Pehaps an end-of-line indication is not reset?
Ray Brownrigg
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To: r-devel-request@stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._