[R-pkg-devel] (How) can you use R file i/o within Fortran code in an R package?

Peter Green m@pjg @end|ng |rom br|@to|@@c@uk
Wed Feb 16 16:53:17 CET 2022


I am developing a package based around several thousand lines of legacy 
Fortran code front-ended with a fairly minimal R function to format 
input and results. In its basic form it is on CRAN, but now I want to 
extend it in a way that will generate copious output over the course of 
the running time of the Fortran code, and I would prefer if possible to 
write this output to (several) files rather than return it through 
arguments to .Fortran.

I have a version using Fortran open, write and close (naturally avoiding 
stderr and stdout), which runs perfectly on several platforms, but 
generates a NOTE in R-hub and Winbuilder:

 > * checking compiled code ... NOTE
 > File ‘Nmix/libs/Nmix.so’:
 >   Found ‘_gfortran_st_close’, possibly from ‘close’ (Fortran)
 >     Object: ‘Nmix-sub3z.o’
 >   Found ‘_gfortran_st_open’, possibly from ‘open’ (Fortran)
 >     Object: ‘Nmix-sub3z.o’
 >   Found ‘_gfortran_st_write’, possibly from ‘write’ (Fortran), ‘print’
 >     (Fortran)
 >     Object: ‘Nmix-sub3z.o’
 >
 > Compiled code should not call entry points which might terminate R nor
 > write to stdout/stderr instead of to the console, nor use Fortran I/O
 > nor system RNGs.
that will presumably cause it to fail submission to CRAN, for reasons I 
understand.

Is there a way that I can use R file i/o from within the Fortran code, 
possibly mediated through a C or C++ wrapper? As I am not fluent in 
these languages or all the concepts involved, if it is possible a recipe 
or template would be most appreciated. To fix ideas, (how) can I write 
100000 integers, separated by white space, to a text file?

My apologies if this is a well-known question already answered, possibly 
in the negative, but my search through the archives failed to find 
anything. Thank you.

Peter Green




More information about the R-package-devel mailing list