I am having difficulty getting R to read a .txt or .csv file that contains apostrophes.
Some of my columns contain descriptive text, such as \"Attends to customers\' n
Thoroughly studying the options in ?read.table will pay off in the long run. The default values for quoting characters is quote = "\"'", which is really only two characters after R parses that expression, single-quote and double-quote. You can remove them both from consideration using quotes=NA
. It's sometimes necessary to also remove the 'comment.char' defaulting to "#", and it may be helpful to change 'as.is' to TRUE to prevent strings from getting converted to factors.
By default, read.table
sees single and double quotes as quoting characters. You need to add quote="\""
to your read.table
call. Or, you could just use read.csv
, which only sees double quotes as quoting characters by default.
Setting the parameter quote="\\" in read.table should do the trick.