title: R: Advantages of using a Fortran subroutine with .Call and C/C++ wrapper instead of .Fortran?
body: <p>I have an R package which uses lots of Fortran subroutines for nested loops of recursive linear algebra computations (depending heavily on BLAS and LAPACK routines). As an interface to Fortran, I use <code>.Fortran</code> function. I just read <a href="http://mazamascience.com/WorkingWithData/?p=1099">Jonathan Callahan's blog post</a> about using <code>.Call</code> instead of <code>.C</code> in case of subroutines written in C/C++, and it got me thinking that would it be better to use <code>.Call</code> interface also when using Fortran subroutines, by writing a simple wrapper in C which then calls the Fortran subroutines?</p>
  
  <p>As said, my Fortran codes are quite simple in a sense that I just play with multidimensional arrays of type double or integer. But I have learned that I must write quite a lot of checks in R side to ensure that everything doesn't crash because of I accidentally forgot to change the storage mode of some matrix to integer or the dimensions of some matrix were changed etc.</p>
  
  <p>Subroutines are written as F90/95.</p>