[Rcpp-devel] Rcpp : passing user-defined c++ class

Yousra El Bachir yousra.elbachir at gmail.com
Tue Feb 21 14:15:53 CET 2017

Hi all,

I am calling from R (say funcR) a c++ function (say funcCpp) which needs
either some programmer-defined c++ class (say programmerClassCpp1, 2,
etc...) or a user-defined c++ class (say userClassCpp). Here is an
illustration of what I am doing:

funcR(..., class="ClassCpp"){

  # do something and then call the c++ function


funcCpp(std::string classCpp){

      case "class1" : point to the programmer defined c++
class programmerClassCpp1; break;
      case "class2" : point to the programmer defined c++
class programmerClassCpp2; break;
      case "new": point to the user defined c++ class userClassCpp; break;
      default : Rcpp::stop("not supported class");

This post


reflects what I need for a function and I am wondering whether it is
possible to do this for a class. The obvious solution is to replicate
manually what has been done in the post to each method of the class (for
instance, work on a vector of functors to the class methods), but I don't
see it as the optimal solution.

Many thanks for any hint,
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/rcpp-devel/attachments/20170221/1f7461ca/attachment.html>

More information about the Rcpp-devel mailing list