Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
538 views
in Technique[技术] by (71.8m points)

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 ?????????????????????

Any help greatly appreciated.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

rs <- dbSendQuery(con, 'set character set "utf8"')

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...