[Rcpp-devel] advice on sharing C++ code across R and Python

David Bellot david.bellot at gmail.com
Fri Apr 27 10:01:20 CEST 2018


In my experience, it's usually much easier to have a stand-alone C++
library and add the Rcpp and Boost.Python layer on top of it. As you said,
NumericVector and other classes are not known in the Python world.

You can always hook in into them from Boost.Python to expose them to Python
but a clear and simple design is to have an independent C++ library and
then you wrap it into all the languages you want.
I found Boost.Python quite similar to Rcpp (I think the second one got
inspiration from the first one ?). So it shouldn't be too hard...

Cheers,
David

On Fri, Apr 27, 2018 at 8:43 AM, Simon Barthelmé <
simon.barthelme at gipsa-lab.fr> wrote:

> Dear list,
>
> I have an R package that's mostly C++ code (using Eigen, but no other
> dependencies) and some glue. We wish to re-use the C++ code for a Python
> package. Most of the external-facing C++ functions are pretty simple:
> essentially they're all variants of:
>
> NumericVector some_matrix_calculation(NumericMatrix a_matrix);
>
> and all the stuff coming in or out are dense vectors and matrices. Note
> that I wrote all this with the idea that the C++ would only be called from
> R, so the C++ bits don't amount to a proper library.
>
> I haven't used Python in years but from what I read there's about a dozen
> different ways now of interfacing Python and C/C++. Obviously none of them
> know about Rcpp objects like NumericVector so I'm guessing it'll have to be
> std::vector<double> in and out, unless there's a better way?
>
> So: does anyone have any experience or advice on sharing C++ code between
> R and Python, short of spinning off the C++ as a stand-alone library and
> writing entirely separate interfaces?
>
> Also, I know you can call R from Python and vice-versa, but we don't want
> to require Python users to install R+dependencies and vice-versa.
>
> Many thanks for any advice!
>
> Best regards
>
> Simon Barthelme
> _______________________________________________
> Rcpp-devel mailing list
> Rcpp-devel at lists.r-forge.r-project.org
> https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/rcpp-devel/attachments/20180427/7569676c/attachment.html>


More information about the Rcpp-devel mailing list