From hb at biostat.ucsf.edu  Fri Oct  3 19:28:58 2014
From: hb at biostat.ucsf.edu (Henrik Bengtsson)
Date: Fri, 3 Oct 2014 10:28:58 -0700
Subject: [Rd] Any penalty for using gzfile() in place of file() for reading?
Message-ID: <CAFDcVCQKaRv=knZe7XcFRjE9x+ZePzijx8o3_g0MrubGXYwMDA@mail.gmail.com>

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



[Rd] Any penalty for using gzfile() in place of file() for reading?
Henrik Bengtsson