1

I'm using the "RMySQL" library in R to load data from a local MySQL DB into R:

con <- dbConnect(MySQL(), user="root", password="****", dbname="twitterdata", host="localhost")
dataframe <- dbGetQuery(con, "SELECT id, plaintext, category FROM table")

When I inspect the dataframe, I see a lot of unformatted characters such as the slanted apastrophe (´) which shows up as ’.

After some research, I discovered that according to this site, some special characters (including the slanted apastrophe) are not part of the ISO-8859-1 standard but of the Windows-1252 standard.

When I run

Sys.getlocale("LC_CTYPE")

in R, it says:

"German_Austria.1252"

Doesn't it already say that I'm on the correct encoding?! In my DB (Default Charset: UTF-8), the apostrophe is encoded well.

I also tried to add a parameter to the dbConnect statement DBMSencoding="utf-8" but with no effect.

When I run

Encoding(x)

in R (where x is the character vector - a sentence), the answer is

"unknown"

Does anybody know now to solve this issue?

Thanks a lot!

6
  • Does this help? Afaik, a ' should be part of iso-8859-x as well as utf-8. You probably need to encode it correctly within R. Commented Jun 3, 2015 at 12:08
  • Yes the ' is part of the iso-8859-x, but not the ´ and the `. The interesing thing is that when I write the data to a file, it's correctly shown again. Commented Jun 3, 2015 at 12:25
  • So, did you try iconv(dataframe [, 1], from = "UTF-8", to = "latin1") as suggested? It's hard to debug without having access to the actual data... Commented Jun 3, 2015 at 13:48
  • Oh man! That works! I don't know how I could overlooked that! Thanks a lot!!! Commented Jun 3, 2015 at 14:23
  • Okay, doesn't work either. When I do that, some entries simply become "NA"... Commented Jun 3, 2015 at 14:42

1 Answer 1

1

Do it:

con <- dbConnect(MySQL(), user="root", password="****", dbname="twitterdata", host="localhost", encoding = "latin1")
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.