R How to estimate csv file size prior to writing it to disk

Viewed 8085

Is there any way in R to estimate the file size of a csv file prior to actually writing it to disk via write.csv or readr::write_csv? I would like to implement a warning if the user accidentially tries to write huge files to disk in a function.

There seems to be some relationship between memory footprint of a dataframe (object.size) and the size on disk, with the latter being considerably larger. However, the larger the object in memory, the smaller the difference. Also, there might be differences related to the structure of the dataframe.

I do not want to force people to download large amounts of data, so please excuse the lack of an reproducible example.

4 Answers
Related