Import and Export for CSV are both broken in Mathematica
- by dreeves
Consider the following 2 by 2 array:
x = {{"a b c", "1,2,3"}, {"i \"comma-heart\" you", "i \",heart\" u, too"}}
If we Export that to CSV and then Import it again we don't get the same thing back:
Import[Export["tmp.csv", d]]
Looking at tmp.csv it's clear that the Export didn't work, since the quotes are not escaped properly.
According to the RFC which I presume is summarized correctly on Wikipedia's entry on CSV, the right way to export the above array is as follows:
a b c, "1,2,3"
"i ""heart"" you", "i "",heart"" u, too"
Importing the above does not yield the original array either.
So Import is broken as well.
I've reported these bugs to [email protected] but I'm wondering if others have workarounds in the meantime.
One workaround is to just use TSV instead of CSV.
I tested the above with TSV and it seems to work (even with tabs embedded in the entries of the array).