[R] escape characters for apostrophes in a .csv file

Duncan Murdoch murdoch.duncan at gmail.com
Wed Apr 23 22:36:08 CEST 2014

On 23/04/2014 4:09 PM, Simon Kiss wrote:
> Hello:
> I have a .csv file that includes some character strings (open ended survey responses) that includes some apostrophe. Using read.csv() the file reads in just fine, except upon being read in the apostrophes are displayed with the double-slash, i.e. 'I've' becomes 'I\\'ve'.  I'd like to print these responess out for a report.  Is there a way that I can have the apostrophes read in as original or print them out without the escape characters.

That sounds very strange.  I would guess that your csv file has 
backslashes in it, not just apostrophes.  You probably need to use 
read.table with appropriate options to interpret the backslashes as 
escape characters.  (Normal CSV files don't escape apostrophes, they are 
enclosed in double quotes, e.g.

"That's strange"

would be what is stored.  R will read this without adding any escapes.

Duncan Murdoch

More information about the R-help mailing list