[R] Calling R (GAMM) from Fortran

2009-11-19 Thread Paul Warren Simonin


   Hello,

     I am currently working on a modeling project using Fortran to run  
large repetitive loops (many DO loops). As part of this process I  
would like to use a model fit in R and currently stored as an R  
object. This is a rather complex model, a GAMM, and I am curious  
whether there is a way to call this model from Fortran. I am not sure  
call is correct terminology, but I would basically like to use this  
GAMM to make a prediction as part of each DO loop. Is this possible? I  
have found instructions, etc. for calling Fortran from R but not vice  
versa.

     Thank you for any information or advice. General advice to  
address this situation is also welcome.

   Thanks again!

   -Paul Simonin

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Calling R (GAMM) from Fortran

2009-11-19 Thread Charlie Sharpsteen
On Thu, Nov 19, 2009 at 12:14 PM, Paul Warren Simonin
paul.simo...@uvm.edu wrote:


   Hello,

     I am currently working on a modeling project using Fortran to run
 large repetitive loops (many DO loops). As part of this process I
 would like to use a model fit in R and currently stored as an R
 object. This is a rather complex model, a GAMM, and I am curious
 whether there is a way to call this model from Fortran. I am not sure
 call is correct terminology, but I would basically like to use this
 GAMM to make a prediction as part of each DO loop. Is this possible? I
 have found instructions, etc. for calling Fortran from R but not vice
 versa.

     Thank you for any information or advice. General advice to
 address this situation is also welcome.

   Thanks again!

   -Paul Simonin


The R library and interpreter are written in C and available using a C
interface.  Therefore, it  would be theoretically possible to call
this interface from Fortran-- however there are details that probably
make a direct call impossible in practice.  This is because
interfacing with R requires passing representations of R objects
(SEXPs) which are far removed from the basic C variable types
supported by standardized C--Fortran interfaces.

 It may be that the only plausible way to approach this problem may
involve writing a set of bindings in C that interface with R and
extract the information you are interested in and then express it
using basing C variables that Fortran can understand.  With such a
system in place your Fortran program would call a set of routines
written in C that called routines from the R libraries and then
reformatted the results and returned them to Fortran.

This is a conclusion based on my limited experience-- not any formal
expertise.  There are definitely others on this list that could
provide a better qualified answer.

Good luck!

-Charlie

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.