[Rcpp-devel] Extending Rcpp with a dummy class

Alessandro Mammana mammana at molgen.mpg.de
Fri Feb 14 11:02:33 CET 2014


Thanks a lot, I misunderstood the document
http://cran.r-project.org/web/packages/Rcpp/vignettes/Rcpp-extending.pdf
.
But there is still a problem when I try to use these classes
definitions in a package.
If these classes are defined in the file classdef.cpp, I somehow need
to add the line #include "classdef.cpp" in the file RcppExports.h.
Because this file is automatically generated, I looked for some Rcpp
attribute that adds this line. Rcpp::depends could be the one, but
I don't see how to use it, since classdef.cpp is not an Rcpp package.
I also tried just to add -I../inst/include in the Makevars and a
header classdef.h in
that directory, but this does not seem to add the desired line.
One again I am lost...
What should I do?


On Thu, Feb 13, 2014 at 4:13 PM, Dirk Eddelbuettel <edd at debian.org> wrote:
>
> 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



-- 
Alessandro Mammana, PhD Student
Max Planck Institute for Molecular Genetics
Ihnestraße 63-73
D-14195 Berlin, Germany


More information about the Rcpp-devel mailing list