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

Dirk Eddelbuettel edd at debian.org
Thu Aug 22 03:36:08 CEST 2013


Hi Luke,

On 22 August 2013 at 00:30, Luke.Domanski at csiro.au wrote:
| 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?

Fair point. I may have missed that.
 
| "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)?

In my experience packages are best.
 
| 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

I think that is orthogonal to how you build the package.

| 	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.

A package can do them at load time.

Dirk
 
| 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.
| 
| 

-- 
Dirk Eddelbuettel | edd at debian.org | http://dirk.eddelbuettel.com


More information about the Rcpp-devel mailing list