[Rd] Re: (PR#1210) an error message from scan() surprised vograno@arbitrade.com.

ripley@stats.ox.ac.uk ripley@stats.ox.ac.uk
Tue, 11 Dec 2001 16:28:45 +0100 (MET)


Original incorrect subject line was

Subject: [Rd] multi.line=FALSE does not work in scan() (PR#1210)

It *does* work quite correctly: this was an erroneous file nd
you got an error, just one you didn't understand.

Please don't use grossly misleading subject lines: they are all that
appear in the BUGS file.


On Tue, 11 Dec 2001 vograno@arbitrade.com wrote:

> The following applies to scan function called with multi.line=FALSE and
> what=list(...).
>
> If 'what' has more members than the number of columns in the file scan()
> keeps reading from the next line of the file despite multi.line=FALSE. Here
> is a transcript of the session:
>
> # attempts to read four field whereas the file, foo, has only three per row
> # This is the "foo" file
> 1 2.1 3.2
> 1 4.1 5.2
> 1 6.1 7.2
>
> > x <- scan("foo", list(integer(0), double(0), double(0), integer(0)),
> multi.line=FALSE)
> Error in scan("foo", list(integer(0), double(0), double(0), integer(0)),  :
> 	"scan" expected an integer, got "4.1"
>
> # That an error will arise is expected, but not of this kind

(Why not?  It tries to read the next item, and finds it can't and reports
so.  Only later does it check it stayed on the same line.)

> # As a side note, it would be more informative if scan() printed the serial
> number of the offending line (this is what S-Plus does).

In fact had scan got to the multiline check, it would have told you:

x <- scan("foo", list(double(0),double(0),double(0),double(0)),
multi.line=FALSE)

Error in scan("foo", list(double(0), double(0), double(0), double(0)),  :
        line 1 did not have 4 elements

> > unlist(R.Version())
[...]

(which took far more space than the standard printout).

Now, the diagnostics could be improved, but it is not a bug to give an
error on erroneous input.

Not something to be tampered with during feature freeze.

-- 
Brian D. Ripley,                  ripley@stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272860 (secr)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595


-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._