[R] File access from within a DLL

Laurens Leerink laurens_leerink at yahoo.com
Fri Nov 1 22:02:37 CET 2002


Is there a recommended method using R header files for opening files from
within a DLL?  I can remember reading something on this topic, but have been
unable to find it in any of the recent FAQs or in the help archive.

I'm using the C open/lseek/read/close functions with the usual C header files

  #include <stdio.h>
  #include <math.h>
  #include <string.h>
  #include <sys/types.h>
  #include <sys/stat.h>
  #include <fcntl.h>
  #include <errno.h>

to read in a binary file.  There are some system dependencies eg

#ifdef Win32
    fd = open(fname, O_RDONLY | O_BINARY);
    fd = open(fname, O_RDONLY);

but until recently this code worked fine under Win2k and Solaris.  I recompiled
the code after upgrading to V1.6 and the code still works fine under Solaris,
but under W2k it fails for larger files.  First thought there was a problem
with the compilers, so followed the instructions (very clear!) in
R-1.6.0/src/gnuwin32/INSTALL, downloaded the latest set of tools and was able
to rebuild R from source.  Results were unchanged.

As a workaround have written an equivalent library in R using readBin/seek as
described in the Data Import/Export manual (works fine but is slower).

Thanks for your help.

Laurens Leerink
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch

More information about the R-help mailing list