jgh781 jgh781 - 1 year ago 80
SQL Question

displaying Japanese characters retrieved from MySQL in R

I am struggling to display Japanese characters in a dataframe, which have been retrieved from a MySQL database using the RMySQL package. Japanese characters display fine if I paste a string from the database into a variable, which then has the Encoding 'UTF-8'. The Encoding of the dataframe column is 'unknown' and I haven't managed to change it using iconv.

A line of the database is:

1.00 20120801 4520000000000.00 1.00 379.00 142.00 北日本フード スーパー極上キムチ 330g

Retrieved using:

rs <- dbSendQuery(con, "select * from sales");
data <- fetch(rs, n=-1)

First row of data:

1 1 20120801 4.52e+12 1 379 142 ?????????????????????\r

Any help greatly appreciated.

Answer Source

The problem seems to be fixed by adding the following line before retrieving that data:

rs <- dbSendQuery(con, 'set character set "utf8"')
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download