[R-pkg-devel] is Fortran write still strictly forbidden?

Jisca Huisman j|@c@@hu|@m@n @end|ng |rom gm@||@com
Thu May 9 08:33:34 CEST 2024


Dear Berwin & Erin,

Thanks for your replies. I should perhaps have clarified - this is for a 
package on CRAN.

In my experience anything with Fortran write will get a NOTE from CRAN's 
auto-check:

Check: compiled code, Result: NOTE
   File 'sequoia/libs/sequoia.so':
     Found '_gfortran_st_write', possibly from 'write' (Fortran), 'print'
       (Fortran)
       Object: 'sequoia.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.


In the past (2018) I've tried to `write` the iteration number to a char 
to then combine into the message send to R with `dplepr`, but when I 
tried to argue this was a false positive as it wasn't writing to a file 
I got the following reply from UL:


> The manual says
>
> <quote>
> In particular, any package that makes use of Fortran I/O will when 
> compiled on Windows interfere with C I/O: when the Fortran I/O support 
> code is initialized (typically when the package is loaded) the C 
> stdout and stderr are switched to LF line endings.
> </quote>
>
> and both of us read too quickly: when the Fortran I/O support code is 
> initialized (typically when the package is loaded) the C stdout and 
> stderr are switched to LF line endings.
> This happens alway, even if you write to another variable.
>
> You could of course write C interface code to do the conversion if you 
> have to rely on write(). 

So what I'm wondering now - has the issue with the switch to LF line 
endings been fixed, and is it OK to use non-file `write`? Because I 
don't really want to make the time to figure out how to 'write C 
interface code to do the conversion' just for some prettier messages...


Thanks for your help!




On Thu, 09/05/2024 06:30, Berwin A Turlach wrote:
> Hi Jisca,
>
> On Wed, 8 May 2024 10:37:28 +0200
> Jisca Huisman <jisca.huisman using gmail.com> wrote:
>
>> I like to use write() in Fortran code [...] But from 'writing R
>> extensions' it seems that there have been quite a few changes with
>> respect to support for Fortran code, and it currently reads:
>>
>> 6.5.1 Printing from Fortran
>>
>> On many systems Fortran|write|and|print|statements can be used, but
>> the output may not interleave well with that of C, and may be
>> invisible onGUIinterfaces. They are not portable and best avoided.
> I am not aware that there were any recent changes regarding printing
> from Fortran recently, or that it was every strictly forbidden (perhaps
> it is for packages that are submitted to CRAN?).  In fact, R-exts.texi
> for R 1.0.0 states pretty much the same as what you quoted from the
> current WRE manual:
>
>    @subsection Printing from Fortran
>    @cindex Printing from C
>
>    In theory Fortran @code{write} and @code{print} statements can be
>    used, but the output may not interleave well with that of C, and will
>    be invisible on GUI interfaces.  They are best avoided.
>
>    Three subroutines are provided to ease the output of information from
>    Fortran code.
>
>    @example
>    subroutine dblepr(@var{label}, @var{nchar}, @var{data}, @var{ndata})
>    subroutine realpr(@var{label}, @var{nchar}, @var{data}, @var{ndata})
>    subroutine intpr (@var{label}, @var{nchar}, @var{data}, @var{ndata})
>    @end example
>
> Cheers,
> 	
> 	Berwin



More information about the R-package-devel mailing list