How can one use R-code and R-functions within C-Code?

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

How can one use R-code and R-functions within C-Code?

moritz.marienfeld
Dear everyone,

the following problem: Our group has written a lengthy program in c++, to which we would like to add some additional features. Because we are not sure if those features are actually useful, we would prefer to take a "quick and dirty" approach just to try them out. The additional feature is that in every iteration of the algorithm membership-probabilities should by calculated by a multinomial logit or probit model. We have tried to get C/C++ code for this, but sadly neither me nor my collegue succeded in obtaining C-code for something, which has certainly already be programmed in C several times.

But we know, that R functions like "multinom" exist, which could do the job. This is why we would like to use R-Code and R-functions within or C++ program if this is possible. So I have actually two questions: Is it feasible to use R-code and R-functions like "multinom" within a c++ program? And if so, what is the best way to implement this (how to get data from C into the R functions, how to execute the R functions within C++, how to transfer the results back to c++)?

Moritz    

Moritz Marienfeld

Viel oder wenig? Schnell oder langsam? Unbegrenzt surfen + telefonieren
ohne Zeit- und Volumenbegrenzung? DAS TOP ANGEBOT JETZT bei Arcor: günstig
und schnell mit DSL - das All-Inclusive-Paket für clevere Doppel-Sparer,
nur  44,85 €  inkl. DSL- und ISDN-Grundgebühr!

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Reply | Threaded
Open this post in threaded view
|

Re: How can one use R-code and R-functions within C-Code?

Prof Brian Ripley
This is discussed in the `Writing R Extensions' manual which ships with
every copy of R.

Yes, it is possible and widely used.  For example, this is how optim() and
nls() work.

See the posting guide, which clearly indicates this is a topic for
the R-devel list.

On Wed, 22 Feb 2006, [hidden email] wrote:

> Dear everyone,
>
> the following problem: Our group has written a lengthy program in c++,
> to which we would like to add some additional features. Because we are
> not sure if those features are actually useful, we would prefer to take
> a "quick and dirty" approach just to try them out. The additional
> feature is that in every iteration of the algorithm
> membership-probabilities should by calculated by a multinomial logit or
> probit model. We have tried to get C/C++ code for this, but sadly
> neither me nor my collegue succeded in obtaining C-code for something,
> which has certainly already be programmed in C several times.
>
> But we know, that R functions like "multinom" exist, which could do the
> job. This is why we would like to use R-Code and R-functions within or
> C++ program if this is possible. So I have actually two questions: Is it
> feasible to use R-code and R-functions like "multinom" within a c++
> program? And if so, what is the best way to implement this (how to get
> data from C into the R functions, how to execute the R functions within
> C++, how to transfer the results back to c++)?


--
Brian D. Ripley,                  [hidden email]
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

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Reply | Threaded
Open this post in threaded view
|

Re: How can one use R-code and R-functions within C-Code?

Romain François
In reply to this post by moritz.marienfeld
Le 22.02.2006 13:25, [hidden email] a écrit :

> Dear everyone,
>
> the following problem: Our group has written a lengthy program in c++, to which we would like to add some additional features. Because we are not sure if those features are actually useful, we would prefer to take a "quick and dirty" approach just to try them out. The additional feature is that in every iteration of the algorithm membership-probabilities should by calculated by a multinomial logit or probit model. We have tried to get C/C++ code for this, but sadly neither me nor my collegue succeded in obtaining C-code for something, which has certainly already be programmed in C several times.
>
> But we know, that R functions like "multinom" exist, which could do the job. This is why we would like to use R-Code and R-functions within or C++ program if this is possible. So I have actually two questions: Is it feasible to use R-code and R-functions like "multinom" within a c++ program? And if so, what is the best way to implement this (how to get data from C into the R functions, how to execute the R functions within C++, how to transfer the results back to c++)?
>
> Moritz    
>
> Moritz Marienfeld
>  

Hi,

For a quick (and pretty not dirty) approach, try Rserve :
http://rosuda.org/Rserve/

Romain

--
visit the R Graph Gallery : http://addictedtor.free.fr/graphiques
Discover the R Movies Gallery : http://addictedtor.free.fr/movies
+---------------------------------------------------------------+
| Romain FRANCOIS - http://francoisromain.free.fr               |
| Doctorant INRIA Futurs / EDF                                  |
+---------------------------------------------------------------+

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html