I have now done some experiments in using Fortran, C++ and R and I think I'm at least half ready to answer my own question now. I ended up writing the diff function (and some other small tests) in both Fortran and C++ and calling it from R.
For starters I think anyone faced with this problem should read Writing R extensions, Rcpp introduction and Rcpp FAQ.
I have now discovered some important points about interfacing the code from R that haven't yet been covered in the answers:
- Rcpp with inline package makes calling C++ from R extremely easy and even takes care of the compiling the extension (see Rcpp FAQ), you can specify everything that you wan't to go into the function and what you wan't to get out.
- Using Rcpp and RcppArmadillo makes it possible to write efficient computations and call them from R very easily with very basic knowledge of C++.
- The R interface to Fortran ".Fortran" is much more limited, you need to use a subroutine to do it and you need to pass all the parameters in that you wan't to get out. That is (as I understand) that you need to preallocate and pass also the result vector(s) (or array) to the subroutine and the subroutine also returns all the parameters. It's not that difficult, but much more error prone, tedious and limited.
- If you wan't to write a portable package you need to use F77 see here.
So as a conclusion: for what I need writing Fortran and C++ (with Armadillo) seems ~ equally easy (or difficult), but interfacing the C++ code from R is a whole lot easier with Rcpp.