It seems most intuitive that .rdata files might be the fasted file format for R to load, but when scanning some of the stack posts it seems that more attention has been on enhancing load times for .csv or other formats. Is there a definitive answer?
Asked
Active
Viewed 1,785 times
8
-
This is a very difficult question to answer correctly. You need to consider converting any given file-reading function into compiled & optimized c- or Fortran code, for example. In addition, since you generally don't have a choice of input format unless you generated the files **in R** in the first place, I'm not sure the answer really matters! – Carl Witthoft Jun 05 '15 at 14:38
1 Answers
8
Not a definitive answer, but below are times it took to load the same dataframe read in as a .tab
file with utils::read.delim()
, readr::read_tsv()
, data.table::fread()
and as a binary .RData
file timed using the system.time()
function:
.tab
with utils::read.delim
system.time(
read.delim("file.tab")
)
# user system elapsed
# 52.279 0.146 52.465
.tab
with readr::read_tsv
system.time(
read_tsv("file.tab")
)
# user system elapsed
# 23.417 0.839 24.275
.tab
with data.table::fread
At @Roman 's request the same ~500MB file loaded in a blistering 3 seconds:
system.time(
data.table::fread("file.tab")
)
# Read 49739 rows and 3005 (of 3005) columns from 0.400 GB file in 00:00:04
# user system elapsed
# 3.078 0.092 3.172
.RData
binary file of the same dataframe
system.time(
load("file.RData")
)
# user system elapsed
# 2.181 0.028 2.210
Clearly not definitive (sample size = 1!) but in my case with a 500MB data frame:
- Binary
.RData
is quickest data.frame::fread()
is a close secondreadr::read_tsv
is an order of magnitude slowerutils::read.x
is slowest and only half as fast asreadr

Phil
- 4,344
- 2
- 23
- 33
-
1
-
@Phil I'm pretty sure that specifying the `colClasses` will improve the read time of the tsv files. It might be worthwhile to include this comparison. – nrussell Jun 05 '15 at 14:37
-
1But how long did it take for R to **generate** each file type? As I mentioned up top, this comparison is moot when someone else sends you files in a given format. – Carl Witthoft Jun 05 '15 at 14:39
-
Thanks for the analysis. Pretty stark differences between. – James Reinhardt - NOAA Affilia Jun 06 '15 at 21:15