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

Comments

Projects
None yet
3 participants
@zross

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

This comment has been minimized.

Show comment
Hide comment
@hadley

hadley Jun 1, 2016

Member

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().

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 changed the title from Encoding in write_csv to Option to add BOM when exporting csv Jun 2, 2016

@hadley hadley changed the title from Option to add BOM when exporting csv to Encoding in write_csv Jun 2, 2016

@hadley

This comment has been minimized.

Show comment
Hide comment
@hadley

hadley Jun 15, 2016

Member

Probably should do in conjunction with #263

Member

hadley commented Jun 15, 2016

Probably should do in conjunction with #263

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

@jimhester

This comment has been minimized.

Show comment
Hide comment
@jimhester

jimhester Jul 6, 2016

Member

Fixed by #448

Member

jimhester commented Jul 6, 2016

Fixed by #448

@jimhester jimhester closed this Jul 6, 2016

@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.