Question

i want to write my own Datatype in C/C++. I generated a small class like this :

#include <Rcpp.h>
using namespace Rcpp;

class Test
{
  public:
  int rows;
  int cols;

  float a[10];

  Test() {};

};


RCPP_EXPOSED_CLASS( Test )

RCPP_MODULE(mod){
  class_<Test>("Test")
    .constructor()
    .field("rows", & Test::rows )
    .field("rows", & Test::cols )
//    .field("a", & Test :: a)
    ;
}

the code is running. But now i want to get the values from a. Ive i understand the documentation correct i have to create a "as" function ? And return a NumericVector ?

I didnt understand the SEXP type, is it a pointer that is "typeless" and can be used in C/c++ and R ?

Was it helpful?

Solution

That's a lot of somewhat elementary questions.

Maybe you should not start with a module and class? How about

  • You could rewrite your class containing a std::vector<double> a.
  • You write a simple 'init()' function that assigns the class to file-local variable (usually a pointer).
  • You write little setter and getter functions, see Rcpp Attributes.

Once a few things are more clear more doing basics, revisit the Rcpp Modules vignette.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top