I am writing an r package that utilizes rcpp.
I have the following class in C++:
using namespace std;
typedef float ffm_float;
typedef double ffm_double;
typedef int ffm_int;
typedef long long ffm_long;
class ffm_model {
public:
ffm_int n; // number of features
ffm_int m; // number of fields
ffm_int k; // number of latent factors
ffm_float *w = nullptr;
bool normalization;
~ffm_model();
};
And I wrote the following RCPP module in order to expose that class to r:
RCPP_MODULE(ffmModelMod){
using namespace Rcpp;
class_<ffm_model>( "ffm_model")
.field("n", &ffm_model::n)
.field("m", &ffm_model::m)
.field("k", &ffm_model::k)
.field("*w", &ffm_model::*w)
.field("normalization", &ffm_model::normalization)
.method("~ffm_model",&ffm_model::~ffm_model)
;
}
When I try to install the package in R, I run into issues since ffm_float *w cannot be cannot directly be converted to a SEXP. From a previous question I asked on here, it was recommended that I try utilizing XPtr to wrap the pointer. However, I'm having a lot of trouble finding helpful documentation, and I don't even know where to start.
In attempt to solve this issue, I have written the following forward declaration, but I have no idea if I'm even heading in the right direction.
namespace Rcpp {
namespace traits{
// Support for wrap
template <typename T> SEXP wrap(const ffm_model<T>&);
// Support for as<T>
template <typename T> class Exporter< ffm_model<T> >;
}
}
Can someone please point me in the right direction? I have already read the RCPP extending vignette.