[Rcpp-devel] Exporter.h cannot convert 'SEXP' to 'const std::vector<double>*' in initialization

Romain Francois romain at r-enthusiasts.com
Thu Oct 24 08:20:34 CEST 2013


Le 23/10/2013 06:12, Jean-Michel.Perraud at csiro.au a écrit :
> Hi,
>
> This has to be a basic question, but I cannot figure out what I am missing nor see quite similar pre-existing posts.
>
> I am trying to create an Rcpp module around a class (generated C++ proxy class). The environment is Rcpp 0.10.5 on Windows, R 3.0.2 x64 and RTools 3.0.
>
> R CMD INSTALL spits the dummy at compilation(?) time when the Exporter things kick in, with the message " cannot convert 'SEXP' to 'const std::vector<double>*' in initialization" on the 'Play' method as per below.
>
> class SimulationExport {
> public:
>    SimulationExport();
>    ~SimulationExport();
>    void Execute(void);
>    void Play(const char* name, const std::vector<double>* values);
> // other methods snipped
> }
>
> RCPP_MODULE(SimulationEx){
>      class_<SimulationExport>( "Simulation" )
> // snipped
>      .method( "play", &SimulationExport::Play)
> // snipped
> }
>
> I don't get why it cannot wrap a vector<double> given how similar it is to "7.2.2.7 Full Example" in the " Seamless R and C++ Integration with Rcpp" book. The same sample code created with Rcpp.package.skeleton compiles (though it fails check on load, BTW). The only difference is the presence of a 'const' modifier before the vector, but removing it does not solve the issue.
>
> Rcpp.package.skeleton('sampleRcpp', module=TRUE, author='J-M')
> library(devtools)
> check('sampleRcpp') # passes past the compilation step.
>
> Cheers,
> J-M

As Dirk said, don't use a pointer to a std::vector<double>.

What do you do in Play with this vector ?
Why did you want to pass it as a pointer ? If this was for performance, 
then passing a reference won't cut it because Rcpp cheats and when you 
pass a reference as a parameter to a function that is Rcpp::export'ed, 
what happens is that the data gets copied.

Could you instead pass down an NumericVector ? The reason is that given 
Rcpp's design, copy semantics of NumericVector are cheap (no data copy). 
Which leads back to hte original question: what does Play want to do 
with this vector ?

Romain


-- 
Romain Francois
Professional R Enthusiast
+33(0) 6 28 91 30 30



More information about the Rcpp-devel mailing list