Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

write.csv with encoding UTF8

I am using Windows7 Home Premium and R Studio 0.99.896. I have a csv file containing a column with text in several different languages eg english, european, korean, simplified chinese, traditional chinese, greek, japanese etc.

I read it into R using

table<-read.csv("broker.csv",stringsAsFactors =F, encoding="UTF-8")

so that all the text is readable in it's language.

Most of the text is within a column called named "content". Within the console, when I have a look

toplines<-head(table$content,10)

I can see all the languages as they are, but when I try to write to a csv file and open it in excel, I can no longer see the languages. I typed in

write.csv(toplines,file="toplines.csv",fileEncoding="UTF-8")

then I opened toplines.csv in excel 2013 and it looked liked this

1   [<U+5916><U+5A92>:<U+4E2D><U+56FD><U+6C1.....
2   [<U+4E2D><U+56FD><U+6C11><U+822A><U+51C6.....
3   [<U+5916><U+5A92>:<U+4E2D><U+56FD><U+6C1.....

and so forth

Would anyone be able to tell me how I can write to a csv or excel file so that the languages that can be read as they are in Excel 2013? Thank you very much.

like image 950
Sunday Avatar asked Sep 10 '25 06:09

Sunday


1 Answers

write_excel_csv() from the readr package, as suggested by @PhiSeu in the comments, has solved it for me.

like image 54
KeenCoder Avatar answered Sep 12 '25 20:09

KeenCoder