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. 2) Does it interface well with R? Is F90/95 supported, or only F77? Thanks, Tamas
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
Tamas K Papp <tpapp at princeton.edu> wrote:> 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... > > 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.I'll answer this from the perspective of someone who uses Fortran 95 regularly. It is a modern language, far more reliable and flexible than Fortran 77 and quite well suited to most scientific problems. I do think it's worth learning, particularly if C is not to your taste. Two free compilers for Fortran 95 are available. It seems that g95 is complete, while gfortran is nearing completion. There are also several high-quality commercial compilers, some of which are free under certain operating systems and/or conditions and others of which (Lahey) are quite inexpensive if one is willing to work from the command line or one's own editor. I can't address questions of R interoperability -- not something I've done. -- Mike Prager, NOAA, Beaufort, NC * Opinions expressed are personal and not represented otherwise. * Any use of tradenames does not constitute a NOAA endorsement.