I am trying to read the following text into R:
"Complete","2014 H2","123456","Local","789123","File of files","A","142","000","Text",""Sharp Yield Rise
-3.7%
Flight to Quality
-5.6%
Liquidity Crisis
-11.1%
Equity Crash
-2.5%
Credit Crisis
-9.7%""^M
The input file is a CMA file (IBM Cognos).
I run the following code.
a <- read.table("aa.cma", header=FALSE, sep=",", stringsAsFactors=FALSE)
I get the following error:
Error in scan(file = file, what = what, sep = sep, quote = quote, dec = dec, :
line xxx did not have 11 elements
The line xxx
reference is for the -3.7%
line from above.
I think this is either due to the quotation mark within the quoted text (see "Sharp" in text above) or having embedded sep=',' and/or (unescaped) '\n' characters within unbalanced unescaped quotes.
Your help is very much appreciated.
read_csv from dplyr seems to do the trick (Read strings that contain a quote in a comma-separated and quote-contained files. For instance, "a","b","c"" where the values are a, b and c")