[R] Using functions written in Fortran in R

Paul Hiemstra paul.hiemstra at knmi.nl
Thu Oct 27 14:02:09 CEST 2011


On 10/27/2011 04:24 AM, John Sorkin wrote:
> Windows XP
> R 2.12
>
> I am trying to understand how I can take a subroutine (i.e. function) I have written in Fortran, and call the function in R.  I need to know (1) where I should store the Fortran subroutine (2) how to prepare the function for use in R, and (3) how to load and call the function. 
>
> There's a large literature that describes how to construct packages (including S Programming by Venables and Ripley, which I have referenced), but everything I have seen appears overly complex and generally geared to R running under Linux where as I run R under Windows XP. 

Hi,

I'm afraid that to some degree running Fortran code from R is complex.
Take a look at the .Fortran functions. Another good tip is to take a
look at an R package which includes a lot of Fortran and see how they
organise their code.

Linux is much more ready for these kinds of solutions, but probably you
could get it to work under Windows. You need a compiler, set all kinds
of enviroment variables etc. Running R under cygwin should make it
possible to use the tutorials/books that are geared towards Linux, for
Windows.

good luck,
Paul

> I want to put R functions and Fortran routines in a library so they can be easily accessed. If, for example, I write a subroutine in Fortran called sqrtvector (n, vector), I want to compile it (to a .dll ?) and then put it in a library so subsequently I can code y <= sqrtvector(nn, x) in my R programs.
>
> Thanks!
> John
>
> John David Sorkin M.D., Ph.D.
> Chief, Biostatistics and Informatics
> University of Maryland School of Medicine Division of Gerontology
> Baltimore VA Medical Center
> 10 North Greene Street
> GRECC (BT/18/GR)
> Baltimore, MD 21201-1524
> (Phone) 410-605-7119
> (Fax) 410-605-7913 (Please call phone number above prior to faxing)
>
> Confidentiality Statement:
> This email message, including any attachments, is for ...{{dropped:20}}



More information about the R-help mailing list