[Rcpp-devel] Are c++ vector types provided by Rccp real c++ type?
bates at stat.wisc.edu
Tue Jun 7 18:05:13 CEST 2011
On Tue, Jun 7, 2011 at 10:44 AM, Héloïse Gauvin
<heloise.gauvin at gmail.com> wrote:
> I am a new user of Rccp. I've been trying to understand since 2 weeks how
> I'll be able to convert a Splus library constructed with multiple C++
> functions (and files) into a nice and free R package.
Great idea. We're happy to help.
> My question seems basic to me but I'll let you judge I get this error
> interface.cpp: In function 'SEXPREC* CreateObjectGen(SEXPREC*, SEXPREC*, S
> EXPREC*, SEXPREC*)':
> interface.cpp:115:87: error: cannot convert 'Rcpp::Fast<Rcpp::Vector<14> >'
> 'int*' for argument '1' to 'int CompGen(int*, int*, int*, int*, int*, int*,
> int*, int*, int*)'
> Do this mean I have to modify every function I am calling from inside
> another c++ function? Is it possible?
Because C++ allows for classes and methods vector objects can be
implemented. In C all one can do is to pass a pointer to an area of
memory and rely on the fact that the called routine will treat it
well. However, C++ has full structures that contain information on
the area of memory, the number of elements, the type of element, the
size of each element, etc.
If you want to get a pointer to the beginning of the area of memory
you use the begin() method. Instead of calling your CompGen function
with arguments like fsPere use fsPere.begin()
Long term it is more desirable to create a structure that would
represent a pedigree (I assume that is what fsPere, fsMere, etc. refer
to) and create methods for that.
> Here I have this code:
> #include"outils.h" // 'outils.cpp' is the place where the function CompGen()
> #include "interface.h"
> #include <stdlib.h>
> using namespace Rcpp ;
> RcppExport SEXP CreerObjetGen(SEXP SInd,SEXP SPere, SEXP SMere, SEXP SSexe)
> NumericVector xSInd(SInd), xSPere(SPere), xSMere(SMere),
> Fast<NumericVector> fSIndividu(xSIndividu), fSPere(xSPere),
> fSMere(xSMere) , fSSexe(xSSexe);
> // the 2nd function I called...
> I used to have this before I had to change them to types provided by Rccp
> int* plIndividu =INTEGER_POINTER(AS_INTEGER(SIndividu));
> int* plPere =INTEGER_POINTER(AS_INTEGER(SPere));
> I've also read the last post on the list... is it because I can't send
> pointers through a function?
> thanks for the help,
> Héloïse Gauvin
> PhD student, Epidemiology
> Rcpp-devel mailing list
> Rcpp-devel at lists.r-forge.r-project.org
More information about the Rcpp-devel