[Rd] Questions on extending Rcpp wrap and as with templates

Dirk Eddelbuettel edd at debian.org
Fri May 2 14:31:13 CEST 2014


On 2 May 2014 at 14:14, Florian Burkart wrote:
| Hi everyone,
| 
| I have been trying to extend Rcpp with my own wrap and as templates.

Good post, wrong list.  Can you please try again on rcpp-devel?  

You may need to subscribe first in order to post (ie pay the "trying to stop
spammers tax").

Dirk

| 
| Two issues:
| 
| 1) I need to explicitly call wrap. Is that expected?
| 
| So for example I wrote this specialization:
| 
| template<> SEXP Rcpp::wrap(std::vector<TimedOptDouble> const& entries) {
| std::vector<double> sec_times;
| std::vector<double> doubles;
| for(auto const& entry : entries)
| {
| sec_times.push_back(entry.GetTime().Seconds());
| TimedOptDouble::OptDouble opt_double(entry.GetOptDouble());
| if(opt_double)
| doubles.push_back(*opt_double);
| else
| doubles.push_back(R_NaReal);
| }
| return List::create(
| Named( "Time" ) = sec_times,
| Named( "Value" ) = doubles);
| }
| 
| First of all, this returns what I believe to be a Rcpp::List object, which
| seems to be converted implicitly to a SEXP. This is the typical behaviour I
| know.
| 
| Unfortunately, when making use of this template, it doesn't work
| implicitly, but I need to explicitly call it.
| 
| So for example
| 
| SEXP GetSunPositions(SEXP a) {
| std::vector<TimedOptDouble> sun_positions;
| ...
| return wrap(sun_positions);
| }
| 
| works, where as
| 
| return sun_positions;
| 
| as last line doesn't. Am I doing something wrong here? I did do the
| declaration before including <Rcpp.h>.
| 
| 2) How to make as work for own types in containers
| 
| The other way around, one can return a std::vector<double> implicitly, but
| how do I return std::vector<MyType>? I tried to define
| 
| template<> MyType as(SEXP);
| 
| But that didn't help, e.g. I had to write my own
| 
| template<> std::vector<MyType> as(SEXP);
| 
| Thanks for help
| Florian
| 
| 	[[alternative HTML version deleted]]
| 
| ______________________________________________
| R-devel at r-project.org mailing list
| https://stat.ethz.ch/mailman/listinfo/r-devel

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



More information about the R-devel mailing list