Getting unwanted characters for apostrophe when reading data from a "|" (pipe) separated text file in R

Viewed 203

I am trying to read data from a text file that contains data in the following format:

583550348352212992|Thu Apr 02 08:43:39 +0000 2015|Ambulance progress 'not fast enough' http://bbc.in/1P1AJyX
583406140337164288|Wed Apr 01 23:10:37 +0000 2015|Children’s hospital builds sleep app http://bbc.in/1BO9jlZ

I'm using the read.table function as follows:

bbchealth <- read.table(file=".../bbchealth.txt", 
                    sep="|", 
                    header = F, 
                    quote="", 
                    fill=F, 
                    stringsAsFactors = F,
                    numerals ="no.loss",
                    col.names = c("TweetId", "Date and Time", "Tweet"))

When I read the file, I see this:

583550348352212992 Thu Apr 02 08:43:39 +0000 2015 Ambulance progress 'not fast enough' http://bbc.in/1P1AJyX
583406140337164288 Wed Apr 01 23:10:37 +0000 2015 Children’s hospital builds sleep app http://bbc.in/1BO

As you can see, the apostrophe in "Childrens" has been changed to ’.

This is the case wherever the apostrophe appears (even in the inverted form).

574407194961039360|Sun Mar 08 03:12:01 +0000 2015|Frankie the dog ‘sniffs out cancer’ http://bbc.in/1COjVHM

is read as

574407194961039360 Sun Mar 08 03:12:01 +0000 2015 Frankie the dog ‘sniffs out cancer’ http://bbc.in/1COjVHM

Here, is converted into ‘ and into ’.

How can I ensure that these symbols are read as they are.

1 Answers

Try encoding="UTF-8" parameter in read.table().

Related