Last active
December 13, 2015 22:49
-
-
Save hadley/4987110 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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