[Rd] How to use R and add-on packages as library in C/C++

Prof Brian Ripley ripley at stats.ox.ac.uk
Mon Aug 21 08:43:56 CEST 2006


On Mon, 21 Aug 2006, Pai-Hsien Hung wrote:
> 
> 
> Thanks for your reply.  
> 
>   I have already read the manual again, and use the R.dll (Ch 8.2.2) (Am I
> right?).  

I don't know, as it depends on the (unstated) version of R where in the 
manual it is. If I were using VC++, I would be more inclined to use the 
(D)COM interface.

> Running the example in the section is OK.  But, when I try to add
> "do_matprod" function in the same example, I don't know what args should put
> in.  The function description in array.c is SEXP attribute_hidden
> do_matprod( SEXP call, SEXP op, SEXP args, SEXP rho), and where I can get
> the definition and description of each variables, call, op, args, ....

That is a private function not in the API nor in the header files.
Indeed, in upcoming versions of R it is not exported from R.dll
(that's what 'attribute_hidden' entails).   Since it is private you will 
not find the information you are seeking in the documentation.

You asked about using code in packages, and this is not in a package.
The time-series functions are in R code, not C code, so I was answering 
the question you actually asked.


> Thanks,
> 
> -----Original Message-----
> From: Prof Brian Ripley [mailto:ripley at stats.ox.ac.uk] 
> Sent: Friday, August 18, 2006 10:32 PM
> To: Pai-Hsien Hung
> Cc: r-devel
> Subject: Re: [Rd] How to use R and add-on packages as library in C/C++
> 
> This is indeed in the manual you mention.  To use R functions and not just 
> standalone libRmath, you need to embed R.
> 
> On Fri, 18 Aug 2006, Pai-Hsien Hung wrote:
> 
> > Hi,
> >   I have a question for building a standalone exe file via C/C++ with R 
> >   and add-on packages in Windows (Compiler is VC).  It may looks like 
> >   ...
> > 
> > #include <R.h>
> > #include <Rmath.h>
> > 
> > int main() {
> >   double *x, *y, z;
> > 
> >   // ... (Variables initial)
> > 
> >   z = ar( x, ...); 
> >   // In this example, I want use the ar (time series) function (in stats
> package) 
> >   // as a library funciton.
> > 
> >   // ... (Other statement)
> > 
> >   return 0;
> > }
> > 
> >   In the "Writing R Extensions" manual, just demo with numerical 
> >   functions, not statistical functions.  I don't know is it possible to 
> >   use statistical functions (Time series at least) or other functions in 
> >   the add-on package, and how to make it.  Thanks for your patient to 
> >   reading this. ^^
> > 
> > 
> 
> 

-- 
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-devel mailing list