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

Jisca Huisman j|@c@@hu|@m@n @end|ng |rom gm@||@com
Wed May 8 10:37:28 CEST 2024


Hello,

I like to use write() in Fortran code to combine text with some integers 
& doubles, to pass runtime information to R in a way that is prettier 
and more legible than with intpr() & dblepr(). In the past any calls to 
write() were strictly forbidden in Fortran code, as apparently it messed 
something up internally (I cannot recall the details). 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.


To be more specific, would the subroutine below be allowed? Is it needed 
to declare R >= 4.0 (?) in the package DESCRIPTION (& then use labelpr() 
instead of intpr() ?) Is there an alternative without write() to get the 
same result?


subroutine Rprint_pretty(iter, x)
     integer, intent(IN) :: iter
     double precision, intent(IN) :: x
     integer :: date_time_values(8), nchar, IntDummy(0)
     character(len=8) :: time_now
     character(len=200) :: msg_to_R

     call date_and_time(VALUES=date_time_values)
     write(time_now, '(i2.2,":",i2.2,":",i2.2)') date_time_values(5:7)
     write(msg_to_R, '(a8, " i: ", i5, "  value: ", f8.2)') time_now, 
iter, x

     nchar = len(trim(msg_to_R))
    call intpr(trim(msg_to_R), nchar, IntDummy, 0)

   end subroutine Rprint_pretty


Thanks!


	[[alternative HTML version deleted]]



More information about the R-package-devel mailing list