I started learning about Rcpp package few days ago and I'm gradually learning how to work with this package. I can see that for many functions in R, a corresponding function has already been written that works very similarly in C++ through the Rcpp package and I guess that is what referred as "Rcpp Sugar". I was trying to use something similar to rep() function(R) in my C++ code and I found that we have something called rep_each in Rcpp sugar:
I then found http://dirk.eddelbuettel.com/code/rcpp/html/classRcpp_1_1sugar_1_1Rep__each.html
The issue is after reading this page, I still have no idea how to use it. Even I don't know what the arguments are. Is there documentation that provides examples for different Rcpp sugar functions?
Thanks very much
Rcpp sugar brings a higher-level of abstraction to C++ code written using the Rcpp API. Rcpp sugar is based on expression templates (Abrahams and Gurtovoy, 2004; Vandevoorde and Josuttis, 2003) and provides some 'syntactic sugar' facilities directly in Rcpp.
The Rep_each
template class is an implementation detail. What you want to use is the rep_each
function. For example:
#include <Rcpp.h>
using namespace Rcpp ;
// [[Rcpp::export]]
NumericVector rep_example( NumericVector x, int n){
NumericVector res = rep_each(x, n) ;
return res ;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With