I have a data.table that is not very big (2 GB) but for some reason write.csv takes an extremely long time to write it out (I’ve never actually finished waiting) and seems to use a ton of RAM to do it.
I tried converting the data.table to a data.frame although this shouldn’t really do anything since data.table extends data.frame. has anyone run into this?
More importantly, if you stop it with Ctrl–C, R does not seem to give memory back.
UPDATE 2019.01.07:
fwritehas been on CRAN since 2016-11-25.UPDATE 08.04.2016:
fwritehas been recently added to the data.table package’s development version. It also runs in parallel (implicitly).According to the detailed benchmark tests shown under speeding up the performance of write.table,
fwriteis ~17x faster thanwrite.csvthere (YMMV).UPDATE 15.12.2015:
In the future there might be a
fwritefunction in thedata.tablepackage, see: https://github.com/Rdatatable/data.table/issues/580.In this thread a GIST is linked, which provides a prototype for such a function speeding up the process by a factor of 2 (according to the author, https://gist.github.com/oseiskar/15c4a3fd9b6ec5856c89).
ORIGINAL ANSWER:
I had the same problems (trying to write even larger CSV files) and decided finally against using CSV files.
I would recommend you to use SQLite as it is much faster than dealing with CSV files:
For further information, see http://cran.r-project.org/web/packages/RSQLite/RSQLite.pdf
You can also use a software like http://sqliteadmin.orbmu2k.de/ to access the database and export the database to CSV etc.
—