Skip to content

fwrite doubles quotes (") in strings to ("") #6723

Description

@thartl-diw

When character variables contain quotes (") in strings, these quotes are doubled in the written csv. I don't know if quotes (") in strings should be supported by data.table.

This are the input and Output CSV after reading and writing the csv with fread and fwrite. All " are doubled except the text classifier ".
Input-CSV:
um_var1,string_var, num_var2
1,"test "nr" string1",4
3,"teststring with double quotes ""Dictator perpetuo"" that are wrongly written when using fread and fwrite",5

using fread and fwrite to read and write the CSV leads to following CSV-file:
Output-CSV:
num_var1,string_var,num_var2
1,"test ""nr"" string1",4
3,"teststring with double quotes """"Dictator perpetuo"""" that are wrongly written when using fread and fwrite",5

The problem remains when using the quote parameter of fread().
This is the code that read and wrote the CSV-files:

`
quote_test <- data.table::fread("string_with_doublequote.csv")

data.table::fwrite(quote_test, "quote_test_out2.csv")
`
quote_test_out2.csv
string_with_doublequote.csv

Activity

  1. MichaelChirico commented on Jan 16, 2025

    @MichaelChirico
    Member

    This is a known issue, I'm choosing one issue as a duplicate (#3509) but there may be others. Thanks for reporting!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions