[Rd] Any penalty for using gzfile() in place of file() for reading?
Henrik Bengtsson
hb at biostat.ucsf.edu
Fri Oct 3 19:28:58 CEST 2014
A question I meant to ask for a very long time:
I have several functions that temporarily open files using file(...,
open="rb"). I'd like to support gzip'ed files also and noticed that
gzfile(..., open="rb") handles also non-compressed files, cf.
help("gzfile"):
For 'gzfile' the description is the path to a file compressed by
'gzip': it can also open for reading uncompressed files and those
compressed by 'bzip2', 'xz' or 'lzma'.
>From simple benchmarking I cannot measure any overhead from using
gzfile(). I assume the only overhead would come from inspecting the
first few bytes in the file. Also, there is no risk that my
non-compressed files have gzip header (by chance), so that is not a
concern.
Does anyone see a reason for not just using gzfile(..., open="rb")
everywhere I use file(..., open="rb") today?
/Henrik
More information about the R-devel
mailing list