Created
April 6, 2018 09:55
-
-
Save romainfrancois/f96238e3704010c62804e168e43e4a9b to your computer and use it in GitHub Desktop.
This file contains hidden or 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; | |
List foo(){ | |
return List::create(1, 2, 3 ) ; | |
} | |
NumericMatrix bar(){ | |
return NumericMatrix(10, 10); | |
} | |
class safevec { | |
public: | |
void push_back(SEXP x){ | |
data.push_back(shelter(x)) ; | |
} | |
List get(){ | |
return wrap(data) ; | |
} | |
private: | |
std::vector<SEXP> data ; | |
Shelter<SEXP> shelter ; | |
}; | |
// [[Rcpp::export]] | |
List stuff() { | |
safevec v ; | |
for( int i=0; i<100; i++) { | |
v.push_back(foo()) ; | |
v.push_back(bar()) ; | |
} | |
return v.get() ; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment