I want to load the rpart package in R from inside C++, use the rpart() function in the rpart package to fit a CART model from inside C++, call the result in C++, and store it for further processing. The code that I tried is given below. I am very new to Rcpp and cpp and would appreciate some input into what I am doing wrong.
#include <RInside.h>                    // for the embedded R via RInside
#include <unistd.h>
using namespace Rcpp;
SEXP testfunc(int argc, char *argv[]) {
    // create an embedded R instance
    RInside R(argc, argv);               
    // running and storing an rpart model utilizing the rpart package from R
    std::string cmd = "rpart::rpart(Kyphosis ~ Age + Number + Start, data = kyphosis);";
    SEXP test = R.parseEval(cmd);
    
    return test;
}
