[Rcpp-devel] vector<string> -> SEXP

Dirk Eddelbuettel edd at debian.org
Tue Nov 10 13:34:59 CET 2009


On 10 November 2009 at 13:03, Romain François wrote:
| On 11/10/2009 12:21 PM, Dirk Eddelbuettel wrote:
| >
| > On 10 November 2009 at 09:38, Romain François wrote:
| > | On 11/09/2009 09:18 PM, Dirk Eddelbuettel wrote:
| > |>
| > |>  On 9 November 2009 at 21:02, Romain François wrote:
| > |>  | I see, thanks. I still think it might be valuable to factor it out as
| > |>  | maybe a static method of RstringVector. Something like :
| > |>  |
| > |>  | static SEXP convertToSEXP( std::vector<std::string>   v) ;
| > |>
| > |>  Oh, I see.
| > |>
| > |>  To eventually have a whole set of helper that convert from STL types to SEXPs
| > |>  and back?  That would be useful.
| > |
| > | Yes. In that case, I'll gradually add them as I need them in RProtoBuf.
| > | The question remains of where. Should I create a separate helper class
| > | that only has static methods
| >
| > Or even just helper functions...
| 
| Deal.

Another thing is that Samperi, after having abandonded his code for
thirty-five months [ during which I picked up Rcpp and made a few releases ]
has just last week come out with RcppTemplate 6.0 and 6.1.  

It's a rewrite, and he added a class RcppSEXP -- I haven't looked closely but
I think that comes close to what you had in mind: from 'anything' to SEXP:


// Return value from getSEXP(type) functions.
class RcppSEXP {
public:
    SEXP sexp;
    int numProtected;
    RcppSEXP(SEXP sexp_, int numProtected_) 
	: sexp(sexp_), numProtected(numProtected_) {}
    RcppSEXP() : sexp(R_NilValue), numProtected(0) {}
};

and

RcppSEXP getSEXP(double);
RcppSEXP getSEXP(int);
RcppSEXP getSEXP(std::string);
RcppSEXP getSEXP(double *, int);
RcppSEXP getSEXP(int *, int);
RcppSEXP getSEXP(double **, int, int);
RcppSEXP getSEXP(int **, int, int);
RcppSEXP getSEXP(RcppDateTime&);
RcppSEXP getSEXP(RcppDate&);
RcppSEXP getSEXP(RcppFrame&);
RcppSEXP getSEXP(RcppZoo&);
RcppSEXP getSEXP(RcppFactor&);

RcppSEXP getSEXP(std::vector<std::vector<double> >&);
RcppSEXP getSEXP(std::vector<std::vector<int> >&);
RcppSEXP getSEXP(RcppMatrix<int>&);
RcppSEXP getSEXP(RcppMatrix<double>&);
RcppSEXP getSEXP(RcppStringVector&);
RcppSEXP getSEXP(std::vector<std::string>&);

// These operations are redundant because they can be accomplished
// using the template function below. Should deprecate.
RcppSEXP getSEXP(RcppDateVector&);
RcppSEXP getSEXP(RcppDateTimeVector&);
RcppSEXP getSEXP(std::vector<double>&);
RcppSEXP getSEXP(std::vector<int>&);
RcppSEXP getSEXP(RcppVector<int>&);
RcppSEXP getSEXP(RcppVector<double>&);

It may be a bit more work to get these into Rcpp, but could be worth it.

Dirk

-- 
Three out of two people have difficulties with fractions.


More information about the Rcpp-devel mailing list