fikar
fikar

Reputation: 11

Korean encoding issues in in R

I am working with R codes that deal with Korean text. Below is a simple code to illustrate the problem:

a <- "안녕"
write.csv(a, "test.csv", fileEncoding = "UTF8")

Running above code gave me a csv file that contains <U+C548><U+B155> instead of 안녕. RStudio already runs the "utf8" unicode as default. Console can print a object nicely, but View(a) gives <U+C548><U+B155>, the uncoded string. The Environment tab also show the uncoded string for a value.

I've tried to run the code with other computer that uses Korean Windows and it somehow works fine. So the language setting probably is the root issue. I actually am using Korean version of Windows 7 but with English as display language. Turning the display language back to default (Korean) actually makes it work! So probably the issue is the language encoding conflict or something in the system.

Is there any fix other than me using Korean Windows in Korean? Thank you very much.

Upvotes: 1

Views: 2519

Answers (1)

SEAnalyst
SEAnalyst

Reputation: 1211

You might want to try using write_csv() within readr package. Using your example, I was able to convert "a" to a dataframe and then save.

a<- "안녕"
a<- as.data.frame(a)
readr::write_csv(a, "test.csv")

The resulting test.csv has this text: a안녕

But this is what you will see if you type 'a' into the console:

> a
                 a
1 <U+C548><U+B155>

Upvotes: 1

Related Questions