[R] problem reading csv file

Petr PIKAL petr.pikal at precheza.cz
Wed Apr 20 14:58:32 CEST 2011


Thank you. 

r-help-bounces at r-project.org napsal dne 19.04.2011 22:00:56:

> Not attached. You might succeed if you rename the file with a .txt 
> extension and re-post.
> 
> Almost surely an encoding issue. We may need your session Info to get 
> "locale".

Maybe you are right. After some further thorough documentation search I 
tried encoding, which was not success. After that I tried fileEncoding = 
UCS-2LE and bingo, that was it.

From file help page

The encodings ‘"UCS-2LE"’ and ‘"UTF-16LE"’ are treated specially,
     as they are appropriate values for Windows ‘Unicode’ text files.
     If the first two bytes are the Byte Order Mark ‘0xFFFE’ then these
     are removed as some implementations of ‘iconv’ do not accept BOMs.

˙ţ1 looks in hex editor like that 0xFFFE so the problem is solved for now.

Thanks again

Petr

> 
> -- 
> David
> On Apr 19, 2011, at 2:47 PM, Petr Pikal wrote:
> 
> > Dear all
> >
> > I have several files which claim to be *.csv (one attached, maybe it
> > will come through) . They can be read to Open Office without much
> > problem, however I can not read them into R. I tried
> > read.table("H2O.CSV", sep=",", dec=".")
> > V1
> > 1 ˙ţ1
> > 2
> > 3
> > ....
> >> read.table("H2O.CSV", sep=",", dec=".", skip=1)
> > Error in read.table("H2O.CSV", sep = ",", dec = ".", skip = 1) :
> > empty beginning of file
> >
> >> readLines("H2O.CSV", 1)
> > [1] "˙ţ1"
> >
> >> readLines("H2O.CSV", 5)
> > [1] "˙ţ1" "" "" "" ""
> >
> >
> > readChar("H2O.CSV", 10)
> > [1] "˙ţ1"
> >> readBin("H2O.CSV", 10)
> > [1] 9.456937e-308
> >
> >
> > This is how first two lines appear in Notepad
> >
> > 1,1.77436423301697,"BV
> > ", 
> > 
91.0779418945313,7.35872077941895,0.178956836462021,1.70007145404816,1.90102112293243
> > 2,1.94783389568329,"VV
> > ", 
> > 
1341.51489257812,9.04244899749756,1.76539707183838,1.90102112293243,3.52783703804016
> > ....
> >
> > The problem seems to be in first item "˙ţ1" which somehow blocks
> > further values to be read.
> >
> > Does anybody have idea what to do or where to look for some help? I do
> > not want to transfer files through spreadsheet manually.
> >
> > Best regards
> > Petr
> > ______________________________________________
> > R-help at r-project.org mailing list
> > https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide 
http://www.R-project.org/posting-guide.html
> > and provide commented, minimal, self-contained, reproducible code.
> 
> David Winsemius, MD
> West Hartford, CT
> 
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide 
http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.



More information about the R-help mailing list