Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Option to write UTF-8-BOM in write_csv() (for excel) #375

Closed
zross opened this issue Mar 1, 2016 · 3 comments
Closed

Option to write UTF-8-BOM in write_csv() (for excel) #375

zross opened this issue Mar 1, 2016 · 3 comments
Labels
feature a feature request or enhancement

Comments

@zross
Copy link

zross commented Mar 1, 2016

I've converted from write.csv to write_csv for a few projects and am finding that write_csv handles special characters differently and results in very odd looking results when opened in Excel. I'm guessing it's related to writing to UTF-8? Here is an example where the dash is an en dash:

dat <- data.frame(a=1:2, b=c("reported – estimate", "updated – estimate"))

write.csv(dat, "d:/junk/writecsv.csv")
readr::write_csv(dat, "d:/junk/readr.csv")

The file from write.csv looks perfect in Excel and when looking at the raw data. The example from readr looks like this in raw:

image

and this in Excel:

image

In my own use case I'm taking advantage of the format_csv function so it's not an easy conversion to go back to write.csv -- I'd love to continue using readr.

@hadley
Copy link
Member

hadley commented Jun 1, 2016

This seems to be a bug in excel: http://stackoverflow.com/questions/6002256/is-it-possible-to-force-excel-recognize-utf-8-csv-files-automatically

But we should add an option to write a BOM to help excel. Possible either an argument write_BOM or a new function: write_excel_csv().

@hadley hadley added feature a feature request or enhancement ready labels Jun 1, 2016
@hadley hadley changed the title Encoding in write_csv Option to add BOM when exporting csv Jun 2, 2016
@hadley hadley changed the title Option to add BOM when exporting csv Encoding in write_csv Jun 2, 2016
@hadley
Copy link
Member

hadley commented Jun 15, 2016

Probably should do in conjunction with #263

@hadley hadley changed the title Encoding in write_csv Option to write UTF-8-BOM in write_csv() (for excel) Jun 15, 2016
@jimhester
Copy link
Collaborator

Fixed by #448

@jimhester jimhester removed the ready label Jul 6, 2016
@lock lock bot locked and limited conversation to collaborators Sep 25, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
feature a feature request or enhancement
Projects
None yet
Development

No branches or pull requests

3 participants