[R] Problems embedding R in a C application

Duncan Temple Lang duncan at research.bell-labs.com
Thu Apr 18 12:49:53 CEST 2002


The embedding of R inside an application is slightly different for
Windows than Unix and it is not guaranteed to stay the same.  So it is
not part of the official R API. This is primarily because I have not
had time to add and _test_ the code to make things the same on both
systems.

If you want to do this under Windows you can take a look at the source
code for the SJava package. Within that you can take a look at the
file REmbed.c and specifically the call to winInit_R(). That is
defined in REmbedWin.c and essentially one replaces the call to
Rf_initEbeddedR() with a call to winInit_R() (currently with no
arguments).

Hopefully this still works with the current version of R (1.4).  It
should unless there have been changes to the way R under Windows is
initialized, but even if it has, the changes probably can be easily
adopted into REmbedWin.c.  I will try to find some time in the future
to provide a Rf_initEmbeddedR() for Windows.

The characteristics of the DCOM interface are different from the
embedding approachj, from what I understand.  The DCOM approach is
fixed however so won't change underneath you. 

 D.



Prof Brian D Ripley wrote:
> On Wed, 17 Apr 2002, Neil Osborne wrote:
> 
> > I've encountered two serious issues that have stopped me in my tracks, and I
> > would be most grateful to anyone who can provide some answers.
> >
> > I am using the examples provided on the page "Testing the Embeddable R
> > Library". I am writing a C application, that I want to embedd R into (I'm
> > not interested in embedding my application in R, that's not an option). I'm
> > developing on a Win2K box. The two problems I've hit (so far!) are these:
> 
> But embedding R in that sense is not supported on Windows, AFAIK.  What is
> supported is the DCOM interface on CRAN.
> 
> > Macro definition (R is using a macro already defined in one of the core
> > windows libraries)
> > Unresolved external - missing definition for func Rf_initEmbeddedR which is
> > prototyped as an extern in EmbeddedRCall.c
> >
> >
> > Here are the issues again (in more detail)
> > ===========================================================
> >
> > 1. Macro re-definition
> >
> > In file ..\include\R_ext\RS.h
> >
> > the line (37):
> >
> > #define ERROR			),error(R_problem_buf);}
> >
> >
> > causes this problem :
> >
> > warning C4005: 'ERROR' : macro redefinition
> >         d:\visualstudio\vc98\include\wingdi.h(93) : see previous definition
> > of 'ERROR'
> 
> Easy!  Just #undef ERROR after the include.  Or use a more selective set of
> headers.
> 
> > 2. Unresolved external:
> >
> > unresolved external symbol _Rf_initEmbeddedR
> >
> > This function is not defined anywhere. Does anyone know how I can init a
> > "session" of R in "embedded" mode (i.e. no direct writing to the console
> > etc) ?
> 
> It *is* defined in src/unix/system.c: note *unix*.
> 
> Answer to Q: use the DCOM interface.
> 
> -- 
> 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 272860 (secr)
> Oxford OX1 3TG, UK                Fax:  +44 1865 272595
> 
> -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
> r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
> Send "info", "help", or "[un]subscribe"
> (in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
> _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._

-- 
_______________________________________________________________

Duncan Temple Lang                duncan at research.bell-labs.com
Bell Labs, Lucent Technologies    office: (908)582-3217
700 Mountain Avenue, Room 2C-259  fax:    (908)582-3340
Murray Hill, NJ  07974-2070       
         http://cm.bell-labs.com/stat/duncan
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list