I need to take a data.frame and export it to a CSV file (or something else, but CSV seemed like the easiest well-formed format) so I can import it into an SQLite database.
However, it looks like write.csv() requires that I write a header line, and SQLite’s .import command requires that I don’t have a header line. So that’s a bit of a mismatch.
Here’s what happens if I try to omit the header line:
> write.csv(mydf, "/tmp/mydf.csv", row.names=F, col.names=F)
Warning message:
In write.csv(mydf, "/tmp/mydf.csv", row.names = F, col.names = F) :
attempt to set 'col.names' ignored
I have to wonder why it’s enforcing that in the first place – the manual says “These wrappers are deliberately inflexible: they are designed to ensure that the correct conventions are used to write a valid file. Attempts to change append, col.names, sep, dec or qmethod are ignored, with a warning.” But I know of nothing in the spec or elsewhere requiring column names – indeed, most tools (Excel, etc.) don’t treat them specially.
If you can’t beat ’em, join ’em.
If you switch to
write.table()(whichwrite.csv()calls anyway) you’re golden: