4

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.

Sunday
  • 89
  • 2
  • 2
  • 5
  • 3
    You could try `write_excel_csv()` from the `readr package`. This is a package from Hadley and RStudio and which helped me. – PhiSeu Aug 29 '16 at 09:18
  • 3
    Here is a little explanation from the help of `write_excel_csv()` : "All columns are encoded as UTF-8. write_excel_csv also includes a UTF-8 Byte order mark which indicates to Excel the csv is UTF-8 encoded." If this doesn't work it might be that you need to activate or install a language package for Excel. – PhiSeu Aug 29 '16 at 09:46
  • Thank you. I have installed readr, but when I type ?write_excel_csv(), I get the error message or ??write_excel_csv(), no results were found. When attempt to use it, eg write_excel_csv(y), I get Error: could not find function "write_excel_csv". It seems like the readr package does not have this function. When I google, I cannot find any more information. Thank you! – Sunday Sep 29 '16 at 08:28
  • After installing a package you have to load it into your script. You can do this with `library(readr)`. There is a help page for this. If you search write_excel_csv in your Help Window of RStudio, you will get `readr::format_csv`. Click on that and you will find the help page for `write_delim` which write_excel_csv is a part of – PhiSeu Sep 29 '16 at 12:24

1 Answers1

4

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

Jeremy Caney
  • 7,102
  • 69
  • 48
  • 77
KeenCoder
  • 41
  • 3