File IO in R

The purpose of this document is to examine the File IO speed and file size of commonly used file IO functions. It includes base R (CSV, RDA, RDS), readr, data.table, and feather. The script was written and run on a iMac (3.2 Ghz 4 core 8 hyperthread i7 4770 processor) with a Crucial MX 200 SSD and 16 GB of RAM.The codebase was borrowed directly from [@rmflight](https://mobile.twitter.com/rmflight) ’s gist and edited for further comparison and testing. Many thanks to [@arun_sriniv](https://mobile.twitter.com/arun_sriniv) for helping me get openMP running.

Writing Files and File Size

Zipping files when saving will save space, but not as much space as RDS/RDA+zipping does and comes at the cost of time. If you have disk space saving in the new feather format is the fastest. Writing to CSV with data.table is extremely fast now, but does come at the expense of file size. base::write.csv() produced files ~20% larger than data.table and readr::write_csv().

Reading Files

Feather was the fastest (on average) at reading the feather formatted data back into R, but it was also the most inconsistent. Second was the RDS format. As with writing, adding compression to cut file size down significally increased the time required to import. data.table was faster than readr, but neither were as fast as RDA/RDS files.

Overall

If you can spare some disk space and the speed of feather is useful to you, it seems like the way to go for now. If disk space is a premium and you don’t mind waiting a little longer then a compressed RDS/RDA file makes the most sense. If you want smaller size and portability, then compressing a csv makes a lot of sense, but is one of the slowest to read in. Base functions for reading/writing CSV files are clearly outpaced by these other methods.

Write Speed

File Size

Read Speed

session_info()
## Session info --------------------------------------------------------------
##  setting  value                       
##  version  R version 3.3.0 (2016-05-03)
##  system   x86_64, darwin13.4.0        
##  ui       X11                         
##  language (EN)                        
##  collate  en_US.UTF-8                 
##  tz       America/Los_Angeles         
##  date     2016-05-06
## Packages ------------------------------------------------------------------
##  package        * version     date       source                          
##  assertthat       0.1         2013-12-06 CRAN (R 3.3.0)                  
##  base64enc        0.1-3       2015-07-28 cran (@0.1-3)                   
##  colorspace       1.2-6       2015-03-11 CRAN (R 3.3.0)                  
##  data.table     * 1.9.7       2016-05-06 local                           
##  DBI              0.4         2016-05-02 CRAN (R 3.3.0)                  
##  devtools       * 1.11.1.9000 2016-05-05 Github (hadley/devtools@c19c6f6)
##  digest           0.6.9       2016-01-08 CRAN (R 3.3.0)                  
##  dplyr            0.4.3       2015-09-01 CRAN (R 3.3.0)                  
##  evaluate         0.9         2016-04-29 CRAN (R 3.3.0)                  
##  feather        * 0.0.0.9000  2016-05-06 Github (wesm/feather@35df40d)   
##  formatR          1.3         2016-03-05 CRAN (R 3.3.0)                  
##  ggplot2        * 2.1.0       2016-05-05 Github (hadley/ggplot2@59c503b) 
##  gridExtra        2.2.1       2016-02-29 cran (@2.2.1)                   
##  gtable           0.2.0       2016-02-26 CRAN (R 3.3.0)                  
##  htmltools        0.3.5       2016-03-21 cran (@0.3.5)                   
##  htmlwidgets      0.6         2016-02-25 cran (@0.6)                     
##  httr             1.1.0       2016-01-28 CRAN (R 3.3.0)                  
##  jsonlite         0.9.19      2015-11-28 CRAN (R 3.3.0)                  
##  knitr            1.12.3      2016-01-22 CRAN (R 3.3.0)                  
##  labeling         0.3         2014-08-23 CRAN (R 3.3.0)                  
##  magrittr         1.5         2014-11-22 CRAN (R 3.3.0)                  
##  memoise          1.0.0       2016-01-29 CRAN (R 3.3.0)                  
##  microbenchmark * 1.4-2.1     2015-11-25 CRAN (R 3.3.0)                  
##  munsell          0.4.3       2016-02-13 CRAN (R 3.3.0)                  
##  plotly         * 3.5.5       2016-05-05 Github (ropensci/plotly@d136b69)
##  plyr             1.8.3       2015-06-12 CRAN (R 3.3.0)                  
##  R.methodsS3    * 1.7.1       2016-02-16 CRAN (R 3.3.0)                  
##  R.oo           * 1.20.0      2016-02-17 CRAN (R 3.3.0)                  
##  R.utils        * 2.3.0       2016-04-14 CRAN (R 3.3.0)                  
##  R6               2.1.2       2016-01-26 CRAN (R 3.3.0)                  
##  Rcpp             0.12.4      2016-03-26 CRAN (R 3.3.0)                  
##  readr          * 0.2.2.9000  2016-05-05 Github (hadley/readr@870058a)   
##  rmarkdown        0.9.6       2016-05-01 CRAN (R 3.3.0)                  
##  scales           0.4.0       2016-02-26 CRAN (R 3.3.0)                  
##  stringi          1.0-1       2015-10-22 CRAN (R 3.3.0)                  
##  stringr          1.0.0.9000  2016-05-05 Github (hadley/stringr@a67f8f0) 
##  tibble           1.0-1       2016-05-05 Github (hadley/tibble@cb38672)  
##  tidyr            0.4.1.9000  2016-05-05 Github (hadley/tidyr@c889f4a)   
##  viridis          0.3.4       2016-03-12 cran (@0.3.4)                   
##  withr            1.0.1       2016-02-04 CRAN (R 3.3.0)                  
##  yaml             2.1.13      2014-06-12 CRAN (R 3.3.0)