Hello,

I have a Reference class defined in R that I am passing as a parameter to a C++ class using Rcpp. I am trying to access the fields of the Reference class from C++ and I'm not sure how to do this.

instrument.R:

Instrument <-setRefClass(
  Class="Instrument",
  fields=list("id"="character", "description"="character")
)

Instrument$accessors(c("id", "description"))

PricingEngine.cpp:

#include <Rcpp.h>

class PricingEngine;

RCPP_EXPOSED_CLASS(PricingEngine)

using namespace Rcpp;

class PricingEngine{
  public:
  PricingEngine(){};
  virtual ~PricingEngine(){};

  double price(SEXP value){
    Rcpp::S4 obj(value);
    // How do I check that SEXP is an instance of Instrument
    // How do use accessors  and fields of Instrument?
    // do pricing here
    return price;
  }

};

RCPP_MODULE(riskceteraPricing) {
   class_<PricingEngine>("PricingEngine")
  .constructor()
  .method("price", &PricingEngine::price)
  ;
}

// R REPL

instrument <- Instrument$new(id="AAPL", description="Apple")
pricingEngine <- new(PricingEngine)
price <- pricingEngine$price(instrument)




_______________________________________________
Rcpp-devel mailing list
Rcpp-devel@lists.r-forge.r-project.org
https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel

Reply via email to