[Rcpp-devel] Problem exposing constructor taking std::vector of user defined class to R using Rcpp-attributes and Rcpp-modules

Luke.Domanski at csiro.au Luke.Domanski at csiro.au
Thu Aug 22 02:30:11 CEST 2013


Thanks for your reply Dirk,

> 
> "Should automatically use available" wrappers/bindings.
> 

Okay.. is it more correct to say "Should use available wrapper to automatically generate bindings"?

> Someone still has to provide the basic as<>() and wrap() code. For
> common types we have done.  For custom types you have to do it.

Is the constructor B::B(SEXP) I implemented not already the implementation of as<B>(), as per described in section 3.1 "Intrusive extension" of Rcpp-extending?

"As part of its template meta programming dispatch logic, Rcpp::as will attempt to use the constructor of the target class taking a SEXP."

Do you think instead or in addition I should be using "Non intrusive extension" as described in section 3.2 e.g:

namespace Rcpp {
	template <> B as( SEXP ){
		Rcpp::Reference in_b(b);
		id=in_b.field("id");
	}
}

I'll give this a try.
  
>
> 
> I would try something simpler.  Rcpp Modules work well with packages,
> so maybe try that first.
> 

Are you suggesting to use Modules and inline cxxfunction() alone, and not through Attributes? Or are you suggesting to use the package skeleton generator on the module (section 3.2 of Rcpp-module.pdf)?

The reason I have chosen the Attributes route vs Modules alone is:
	1) I have done the Rcpp implementation for a person who is not familiar with C++, so would like to keep a R Reference Class version of the code side by side in the source file (using Attributes supported /*** R {R code} */), so they can do their research work/updates in R and later translate the changes to C++ for performance
	2) There are global initialisation tasks that are just simpler from R (loading data files), which can be run by default on sourceCpp() invocation by placing them in /*** R */ comments, and having them calling a simple C++ function in the same source file, exposed via //[[Rcpp:export]], which is used to dump their results into the C++ environment.

So "simpler" might only be simpler for the toy example I've provided, not the real code. In any case, I'll start trying some of your suggestions out, and let you know how I go.

Cheers,
Luke.




More information about the Rcpp-devel mailing list