[Rcpp-devel] Rcpp modules and parsing an object back and forth between R & C++
Hadley Wickham
h.wickham at gmail.com
Wed Feb 20 18:57:04 CET 2013
>> Until that happens, is it possible to write my own as and wrap methods?
>>
>
> Sure.
>
> For as, You can get a Simple* using this:
>
> Simple* obj = as_module_object<Simple>(x) ;
>
> For the details, see as.h, this will call this:
>
> template <typename T> object<T> as_module_object(SEXP x){
> return (T*) as_module_object_internal(x) ;
> }
>
> and then this:
>
> namespace internal{
> void* as_module_object_internal(SEXP obj){
> Environment env(obj) ;
> SEXP xp = env.get(".pointer") ;
> return R_ExternalPtrAddr(xp );
> }
> }
>
> which uses the way we structured the c++ class around the reference class.
>
> but writing RCPP_EXPOSED_AS(Simple) is enough I think so that you get
> "as<Simple>" directly.
Awesome - thanks! That works perfectly.
Hadley
--
Chief Scientist, RStudio
http://had.co.nz/
More information about the Rcpp-devel
mailing list