[Rcpp-devel] Extending Rcpp with a dummy class

Dirk Eddelbuettel edd at debian.org
Thu Feb 13 16:13:33 CET 2014


On 13 February 2014 at 15:55, Alessandro Mammana wrote:
| Suppose that for any reason I want to define my own vector class like this:
| 
| template<typename T>
| struct Vec {
|     T* ptr;
|     int len;
| };

Conceptually that is about the same as our vectors. 

| so, without owning memory but just pointing to some (hopefully valid)
| area of memory.
| How can I extend Rcpp with this class so that I can have R vectors
| automatically converted to these vectors?
| The obvious answer is "read "extending Rcpp" instead of bothering us",

Precisely. :)

And look at the working examples, eg on the Rcpp Gallery I have posts doing
this for Boost DateTime, and for sparse Armadillo matrices.  Look at other
packages. The most full-featured are probably RcppArmadillo and RcppEigen.

| but the compiler complains and says:
| error: 'Vector' is not a member of 'Rcpp'
| 
| this is probably because I still did not import Rcpp.h, but in

Correct.

| "extending Rcpp" they say to include Rcpp.h only after defining my
| classes, so how should I do?

Re-read it. You misunderstood that statement. RcppCommon is used for some
forward declarations. You use it here to replace Rcpp.h.  Won't work.

Dirk

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


More information about the Rcpp-devel mailing list