[R] Handling special characters in reading and writing to CSV

David Winsemius dwinsemius at comcast.net
Wed Feb 5 22:57:01 CET 2014


On Feb 5, 2014, at 2:10 AM, Venkata Kirankumar wrote:

> Hi David,
>  
> In CSV RFC 4180 format if any ‘ or “ character is there then character will go with escape character so CSV will distinguish properly.
>  
> I will try with read.fwf once because with redline I am facing same issue.
>  
> Thanks & Regards,
> D V Kiran Kumar.

I said 'readLines' not 'redline'.

It appears to me that read.table (which is a wrapper to scan currently read files that conform to htat standard, i.e. doubled quotes are treated as if they were escaped.

> read.table(text= '"aaa","b""bb","ccc"' ,sep=",")
   V1   V2  V3
1 aaa b"bb ccc

> read.table(text= "'aaa','b''bb','ccc'" ,sep=",")
   V1   V2  V3
1 aaa b'bb ccc


-- 
David.

> 
> On Wed, Feb 5, 2014 at 3:14 AM, David Winsemius <dwinsemius at comcast.net> wrote:
> 
> On Feb 4, 2014, at 7:58 AM, Venkata Kirankumar wrote:
> 
> > Hi All,
> >
> >
> > I have some data with different special characters, newline character, and
> > different language characters in a CSV file like `~!@#$%^&*|
> > ()-_+={[}]|\:;""'<,>.?/
> > in data, while I am trying to read this CSV and trying to do calculations I
> > am not able to get this data as there in single cell. I found something
> > like RFC 4180 format can help to solve this problem.
> >
> >
> >
> > If anyone can give suggestion related to handling these special characters
> > it will be help full for me
> >
> 
> I'm having a difficult time understanding your expectations and thedata situation. If it's a "csv file",  then how can all three of <comma>, <single-quote>, and <double-quote> be properly distinguished when they are also part of the data?
> 
> 
> You might consider using readLines (from base) or read.fwf (from the utils package)
> 
> 
> 
> >
> >
> > Thanks in advance,
> >
> > D V Kiran Kumar
> >
> >       [[alternative HTML version deleted]]
> >
> > ______________________________________________
> > 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
> Alameda, CA, USA
> 
> 

David Winsemius
Alameda, CA, USA




More information about the R-help mailing list