[Rcpp-devel] Are c++ vector types provided by Rccp real c++ type?

Douglas Bates 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:
> Hi,
> 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
> message:
> interface.cpp: In function 'SEXPREC* CreateObjectGen(SEXPREC*, SEXPREC*, S
> interface.cpp:115:87: error: cannot convert 'Rcpp::Fast<Rcpp::Vector<14> >'
> to
> '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()
> is
> #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),
> xSSexe(SSexe);
>     Fast<NumericVector> fSIndividu(xSIndividu), fSPere(xSPere),
> fSMere(xSMere) , fSSexe(xSSexe);
>  ....
>     CompGen(fSInd,fSPere,fSMere,fSSexe,fInd,fpere,fmere,fsexe,&lNIndividu);
> //  the 2nd function I called...
> __________
> I used to have this before I had to change them to types provided by Rccp
> (NumericVector):
>  int* plIndividu    =INTEGER_POINTER(AS_INTEGER(SIndividu));
>     int* plPere        =INTEGER_POINTER(AS_INTEGER(SPere));
>   etc...
> 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
> --
> Héloïse Gauvin
> PhD student, Epidemiology
> _______________________________________________
> Rcpp-devel mailing list
> Rcpp-devel at lists.r-forge.r-project.org
> https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel

More information about the Rcpp-devel mailing list