Skip to content

Instantly share code, notes, and snippets.

@hadley
Last active December 13, 2015 22:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hadley/4987110 to your computer and use it in GitHub Desktop.
Save hadley/4987110 to your computer and use it in GitHub Desktop.
#include <Rcpp.h>
using namespace Rcpp;
class Simple {
double x;
public:
Simple(double x_): x(x_) {}
Simple(SEXP x_): {
}
double times (double i) const {
return x * i;
}
operator SEXP() {
}
};
RCPP_MODULE(SimpleModule) {
class_<Simple>( "Simple")
.constructor<double>()
.const_method("times", &Simple::times)
;
}
// [[Rcpp::export]]
double times2(const Simple& x) {
return x.times(2);
}
// [[Rcpp::export]]
Simple two() {
return Simple(2);
}
/*** R
s1 <- Simple$new(5)
s2 <- two()
s1$times(2)
s2$times(2)
times2(s1)
times2(s2)
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment