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

write_csv should have option to quote character variables #653

Closed
rmcd1024 opened this issue Apr 22, 2017 · 9 comments
Closed

write_csv should have option to quote character variables #653

rmcd1024 opened this issue Apr 22, 2017 · 9 comments
Labels
feature a feature request or enhancement write ✏️

Comments

@rmcd1024
Copy link

Perhaps I've missed an option, but I don't see how to have write_csv quote strings. This creates problems when strings look like integers.

library(readr)
write_csv(data.frame(a=c(rep("10", 1000), "01")), 'test1.csv')
x1 = read_csv('test1.csv')  ## a imported as integer, breaking last observation
write_csv(data.frame(a=c("01", rep("10", 1000))), 'test2.csv')
x2 = read_csv('test2.csv')  ## a imported correctly as character

Obviously in the read statements one could set guess_max=Inf, but it would be helpful to write quoted strings in the first place.

@jimhester jimhester added the feature a feature request or enhancement label Dec 7, 2017
@jimhester
Copy link
Collaborator

Ok, I agree it should be possible to force quoting if desired.

@jxu
Copy link

jxu commented Aug 2, 2019

Agreed. See quote argument of write.table.
I think there should be three options: Always quote character vectors, quote when needed (the current default), and never quote (dangerous, but here to mimic the functionality of write.table).

@bbolker
Copy link

bbolker commented Oct 23, 2020

+1000. Protecting text fields with commas in them is super-important! Falling back to write.csv() now ...

@jimhester
Copy link
Collaborator

@bbolker readr already quotes text fields with commas automatically, this issue is about forcing quoting even if it isn't strictly needed.

@bbolker
Copy link

bbolker commented Oct 23, 2020

sorry, I ran into some issues last night that made me think otherwise, but it was late. (Actually I think the problem was OpenOffice deciding it should split fields on semicolons as well as commas ...)

@mmuurr
Copy link

mmuurr commented Mar 21, 2021

I'm curious if this open issue is truly open, or if there's a workaround that's commonly used (apart from write.csv and family). I, too, would like to strictly enforce quote-wrapping of certain character columns while writing those columns...

@jimhester
Copy link
Collaborator

One straightforward way to do this is to call base::dQuote() or glue::double_quote() on the columns you want to quote before passing to readr.

@philpav
Copy link

philpav commented Jun 25, 2021

Is there still no built-in way for forcing quotes on all columns?

@sjackman
Copy link

Is there still no built-in way for forcing quotes on all columns?

write_csv(x, file, quote = "all")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature a feature request or enhancement write ✏️
Projects
None yet
Development

No branches or pull requests

7 participants