Skip to content

Help on interfacing C++ with R

2 messages · Sun.Bing@epamail.epa.gov, Roger Bivand

#
On Mon, 13 Mar 2006 Sun.Bing at epamail.epa.gov wrote:

            
Simpler is easier, all this std stuff gets in the way. The problem is that 
R is passing pointers (probably) to doubles, not simple integers. As far 
as I can see, you need to change the 

.C("testIntDivision", 4, 2);

to make sure your numbers are integers (as.integer()) is OK), and the 
function itself (provided that it is visible, and I've no idea if this is 
the case, to pointer arguments:

int testIntDivision(int&, int&); // untried

then pick out the integer values at those addresses. It'll be one or both 
of these problems (I am not fluent in C++, but the same principles apply 
to C). 

I would be concerned about exporting any competing main to load 
dynamically into R too, could you compile the code in two files, one the 
code to load into R, the other with main calling your code, and *only* 
load what needs to be inside R?