I was trying to expose my C++ class through Rcpp by building a package. It seems that module is not allowed in RStudio auto-generated template. For example, if we compare the NAMESPACE file generated by Rcpp.package.skeleton(myPackage, module=TRUE)
and by RStudio, importFrom(Rcpp, loadModule)
is not in the RStudio NAMESPACE file. Did I miss something? How can I enable RStudio to generate module allowed package template?
Here is a minimal example to show my C++ codes in case someone would like to try it in RStudio
class Student{
private:
double age;
double GPA;
public:
Student(double age_, double GPA_):age(age_),GPA(GPA_){}
double sum(double x, double myGPA){
GPA = myGPA;
return GPA + x;
}
double times(double x, double myage){
age = myage;
return age*GPA*x;
}
};
RCPP_MODULE(my_module){
class_<Student>("Student")
.constructor<double, double>()
.method("sum", &Student::sum)
.method("times",&Student::times);
}