[R-sig-DB] Fortran ACCESS='DIRECT' for importing Binary Files
Dirk Eddelbuettel
edd @end|ng |rom deb|@n@org
Thu Apr 17 00:04:56 CEST 2014
On 16 April 2014 at 14:58, Jared Stabach wrote:
| Is there a command similar to Fortran's Access='DIRECT' command for reading
| binary files in R? I am interested in writing a program to access specific
| parts of a binary file, where many years of results are bound together in
| one file.
I have no idea what
Fortran's Access='DIRECT'
is or does, and suspect this question belongs onto r-devel instead .
That said, I may have devised such a simple binary file format for our use at
work where we frequently need to read large matrices (and typically less
frequently write them in batch jobs).
So I write out a header with a few fixed ints about dimension and type, and
then just have one large read of rows * cols elements of size double. And
the nice thing about R is that you can do all of this in R code (!!) via
gzfile() to open a compressed file
readBin() to read int or double
so no need to go to C or Fortran. See the docs on help(connection) and
help(readBin). (And yes, the format is accessible from C/C++ or other
languages such as Python too provided they can read binary blobs from gzip'ed
file)
Dirk
--
Dirk Eddelbuettel | edd using debian.org | http://dirk.eddelbuettel.com
More information about the R-sig-DB
mailing list