It is straight forward to call a Fortran subroutine from R using .Fortran
and there are examples available online. However, I haven't found any direct way to call a Fortran function from R.
Currently, I use an interface for that, which gets the Fortran function and uses it in a subroutine, but it is very time consuming to do so for all external functions.
Is there an elegant way to call Fortran functions directly from R?
With .Fortran
(and .C
) it is not possible to use Fortran functions, as noted in the documentation:
Note that the compiled code should not return anything except through its arguments: C functions should be of type void and Fortran subprograms should be subroutines.
Using .Call
(and .External
) it is possible to call Fortran functions, but it's fair to say that doing this makes writing a subroutine wrapper for the Fortran function look trivial: minimally you'll be writing a C wrapper to be invoked in the middle (making this another "indirect" Fortran function call - directly calling a Fortran function will require even more effort).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With