[RQt-devel] Rcpp

Romain Francois romain.francois at dbmail.com
Wed Jan 20 11:05:13 CET 2010


On 01/19/2010 03:34 PM, Michael Lawrence wrote:
> Thanks for passing this along. Rcpp has come a long way. It could be
> very useful as we add more type conversions. The inline compilation is
> also cool for experimentation.

Hi,

Possibly. For type conversion, we have the magic "as" :

template <typename T> T as( SEXP m_sexp)

so that we do things like :

SEXP foo ;
int x = as<int>( foo ) ;

the templateness gives the possibility to add other converters, so that

Whatever y = as<Whatever>( foo ) ;


.. and since all our RObject's implement the operator SEXP() for 
implicit conversion to SEXP, we can do this for free :

CharacterVector x(1) ; x[0] = "foo" ;
std::string y = as< std::string >( x ) ;


One other thing I thought that could help (although I have not poked 
deeply into your code yet), is the templated external pointer class.

SEXP x = ... ; /* an external pointer holding a Foo object */
XPtr<Foo> p(x) ;
p->bar() ;     /* where bar is a method of Foo */

see 
http://romainfrancois.blog.free.fr/index.php?post/2010/01/08/External-pointers-with-Rcpp 
for details.

Romain

> Michael
>
> On Tue, Jan 19, 2010 at 1:50 AM, Romain Francois
> <romain.francois at dbmail.com <mailto:romain.francois at dbmail.com>> wrote:
>
>     Hello,
>
>     I just wanted to draw your attention to the new version of Rcpp, that I
>     think might be useful for qtinterfaces (maybe not).
>
>     Rcpp has been completely redesigned over the holidays (while keeping the
>     existing interface). Now we have many C++ classes that basically act as
>     proxy classes for the SEXP they encapsulate. So that the object takes
>     care of protection/release to the garbage collection.
>
>     We cover just about every (useful) SEXP type. For example, manipulating
>     a character vector can look like this :
>
>     /* creating a character vector of two elements */
>     Rcpp::CharacterVector x(2);
>     x[0] = "foo" ;
>     x[1] = "bar" ;
>
>     Romain



-- 
Romain Francois
Professional R Enthusiast
+33(0) 6 28 91 30 30
http://romainfrancois.blog.free.fr
|- http://tr.im/KfKn : Rcpp 0.7.2
|- http://tr.im/JOlc : External pointers with Rcpp
`- http://tr.im/JFqa : R Journal, Volume 1/2, December 2009



More information about the Qtinterfaces-devel mailing list