[R] R and Fortran 9x -- advice

Prof Brian Ripley ripley at stats.ox.ac.uk
Fri Nov 10 08:29:16 CET 2006


On Thu, 9 Nov 2006, Tamas K Papp wrote:

> Hi,
>
> I found some bottlenecks in my R code with Rprof.  First I wanted to
> rewrite them in C, but a colleague keeps suggesting that I learn
> Fortran, so maybe this is the time to do it...
>
> I like to learn new languages and do it fairly quickly.  I would
> appreciate the advice of others about these questions:
>
> 1) I hear bad things about Fortran.  Sure, F77 looks archaic, but
> F90/95 seems nicer.  Is it worth learning, especially when I plan to
> use it mainly from R?  Dusting off my C knowledge would take a bit of
> time too, and I never liked C that much.

This is a matter of taste: you would need one of C, C++ or Fortran.
Of those C is most portable, and for inner computations called from R 
there will be little difference between the three in the code you write.

> 2) Does it interface well with R?  Is F90/95 supported, or only F77?

Please see `Writing R Extensions' for a full answer.  F90/95 is supported 
on OSes that support it.  As gcc4 is becoming more widely used, its 
gfortran provides (incomplete) F95 capabilities, but older Linuxen (e.g. 
FC3) do not come with F95 support.  It is possible to install suitable 
a compiler on Windows.

There are a couple of CRAN packages with F90 sources, and it seems the 
binary build systems have been set up to cope with these (thanks, Uwe).

-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595



More information about the R-help mailing list