We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
As far as I can tell the .factory method for Rcpp Modules is not documented yet. Recently I wrote the following example for a SO answer:
.factory
#include <Rcpp.h> using namespace Rcpp; // abstract class class Base { public: virtual ~Base() {} virtual std::string name() const = 0; }; // derived class class Derived1: public Base { public: Derived1() : Base() {} virtual std::string name() const { return "Derived1"; } }; // derived class class Derived2: public Base { public: Derived2() : Base() {} virtual std::string name() const { return "Derived2"; } }; Base *newBase( const std::string &name ) { if ( name == "d1" ){ return new Derived1 ; } else if ( name == "d2" ){ return new Derived2 ; } else { return 0 ; } } RCPP_MODULE(mod) { Rcpp::class_< Base >("Base") .factory<const std::string&>(newBase) .method("name", &Base::name) ; } /*** R (dv1 <- new(Base, "d1")) dv1$name() (dv2 <- new(Base, "d2")) dv2$name() */
Would you be interested in a PR that adds something along these lines to the Rcpp modules vignette?
The text was updated successfully, but these errors were encountered:
That sounds like a useful addition.
Sorry, something went wrong.
No branches or pull requests
As far as I can tell the
.factory
method for Rcpp Modules is not documented yet. Recently I wrote the following example for a SO answer:Would you be interested in a PR that adds something along these lines to the Rcpp modules vignette?
The text was updated successfully, but these errors were encountered: