Skip to content

strange scan, count.fields

2 messages · Adrian Trapletti, Martin Maechler

#
Does anybody understand what's going on here:

I have the following ascii file called "y.txt"


"USD-DEM" "USD-JPY" "DEM-JPY"
 0.344901 4.78712 4.442
 0.345715 4.7882 4.44189
 0.350657 4.79065 4.44177
 0.35347 4.79065 4.43616
 0.35368 4.78957 4.43622
 0.35361 4.78982 4.43669
 0.353821 4.79036 4.43622
 0.352767 4.78899 4.43634
 0.353119 4.78916 4.43545


In R I do the following:


wu161215{adrian}28: R

R : Copyright 1999, The R Development Core Team
Version 0.64.2  (July 3, 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.
Error: "scan" expected a real got ""USD-DEM""
[1] TRUE
Read 27 items
[1] FALSE
scan seems to produce some side-effect (not properly close the file?)
I am using Redhat 5.2 and in general R seems to be rather stable...

Thanks
Adrian

--
Adrian Trapletti, Vienna University of Economics and Business
Administration, Augasse 2-6, A-1090 Vienna, Austria
Phone: ++43 1 31336 4561, Fax: ++43 1 31336 708,
Email: adrian.trapletti@wu-wien.ac.at



-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
#
Adrian, you seem to report several things at once,...

I think, first you really don't want scan but rather read.table
with your file
which gives

R> str(read.table("y.txt",head=T))
`data.frame':  9 obs. of  3 variables:
 $ USD-DEM: num  0.345 0.346 0.351 0.353 0.354 ...
 $ USD-JPY: num  4.79 4.79 4.79 4.79 4.79 ...
 $ DEM-JPY: num  4.44 4.44 4.44 4.44 4.44 ...

---------

Then you report that  scan() leaves something ``behind'' {open file, ??}
after stopping with an error.
This is clearly a bug and is still present in the current 0.65 snapshot.
After a few tests, I see that the problem seems to happen only
(sometimes) when the text leading to the error contains a ` " ' .
The following is even simpler :

 write(c(paste("\"", LETTERS[1:3],"\"", sep=""),1:3), nc=3)
 scan("data")         # gives error as it should
 count.fields("data") # will be wrong
 count.fields("data") # is now ok : 3 3

Gives (in 0.65 snapshot)

    >  write(c(paste("\"", LETTERS[1:3],"\"", sep=""),1:3), nc=3)
    >  scan("data")         # gives error as it should
    Error: "scan" expected a real got ""A""
    >  count.fields("data") # will be wrong
    [1] 4 3
    >  count.fields("data") # is now ok : 3 3
    [1] 3 3

--> I'll report to R-bugs
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._