[Rcpp-devel] advice on sharing C++ code across R and Python
Simon Barthelmé
simon.barthelme at gipsa-lab.fr
Fri Apr 27 09:43:41 CEST 2018
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
More information about the Rcpp-devel
mailing list