Skip to content

Instantly share code, notes, and snippets.

@romainfrancois
Created April 6, 2018 09:55
Show Gist options
  • Save romainfrancois/f96238e3704010c62804e168e43e4a9b to your computer and use it in GitHub Desktop.
Save romainfrancois/f96238e3704010c62804e168e43e4a9b to your computer and use it in GitHub Desktop.
#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