Consider the following comma separated file. For simplicity let it contain one line:
'I am quoted','so, can use comma inside - it is not separator here','but can\'t use escaped quote :=('
table <- read.csv(filename, header=FALSE)
table <- read.csv(filename, header=FALSE, quote="'")
"incomplete final line found by readTableHeader on table"
The escapes which are interpreted are the control characters
‘\a, \b, \f, \n, \r, \t, \v’, ...
... Any other escaped
character is treated as itself, including backslash
One possibility is to use
readLines() to get everything read in as is, and then proceed by replacing the quote character by something else, eg :
tt <- readLines("F:/temp/test.txt") tt <- gsub("([^\\]|^)'","\\1\"",tt) # replace ' by " tt <- gsub("\\\\","\\",tt) # get rid of the double escape due to readLines
This allows you to read the vector tt in using a
zz <- textConnection(tt) read.csv(zz,header=F,quote="\"") # give text input close(zz)
Not the most beautiful solution, but it works (provided you don't have a " character somewhere in the file off course...)