analyticsPierce
analyticsPierce

Reputation: 3025

How to export a csv in utf-8 format?

I am trying to export a data.frame to a csv with utf-8 encoding. I have tried generating the file with write.csv with no success and the help(write.csv) did not mention any specific advice on creating that specific output. Here is my current export line.

write.csv(prod_out, file="product_output.csv",append=FALSE,eol="\r")

Any advice you can offer is appreciated.

Upvotes: 27

Views: 86796

Answers (3)

ay__ya
ay__ya

Reputation: 463

You can try this solution:

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

Upvotes: 8

Michal J Figurski
Michal J Figurski

Reputation: 1351

This question is pretty old - I guess things have changed a lot since 2010. Anyway, I just came across this post and I happen to know the solution. You just add fileEncoding = "UTF-8" option directly to write.csv.

Upvotes: 77

mbq
mbq

Reputation: 18628

Try opening a UTF8 connection:

con<-file('filename',encoding="UTF-8")
write.csv(...,file=con,...)

Upvotes: 20

Related Questions