[R] Strange problems with external Fortran routine

Duncan Murdoch dmurdoch at pair.com
Thu Mar 7 13:48:49 CET 2002


Here's a solution that took a while to find; I wanted to write it to
the list so it'll be available for people in the future.

Summary:  In external Fortran code, use SUBROUTINEs, don't use
FUNCTIONs.

A colleague had bizarre things happening in uniroot() (a root finding
routine), which she used to call an R function that called a Fortran
routine to do some calculations.  For example, the function sometimes
worked, but didn't work when a print() statement was added to it.

We eventually tracked down the problem to the fact that she had
declared the Fortran routine to be a real*8 function, instead of a
subroutine.  Apparently it was returning a value in some way that R
didn't expect, and this was causing R to act strangely.

This is mentioned in the R Extensions manual, but most of the examples
there are in C, so it wasn't obvious.

Duncan Murdoch
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list