I have tried this:
#include <Rcpp.h>
using namespace Rcpp;
// [[Rcpp::export]]
NumericVector difflag(NumericVector x, int lag) {
int n = x.size();
NumericVector out(n-lag);
for(int i=0; i<(n-lag); i++) {
out[i] = x[i+lag] - x[i];
}
out.attr("class") += "myclass";
return out;
}
It gives me an error:
all.cpp: In function ‘Rcpp::NumericVector difflag(Rcpp::NumericVector, int)’:
all.cpp:64:26: error: no match for ‘operator+=’ in ‘Rcpp::RObject::attr(const string&) const((* & std::basic_string<char>(((const char*)"class"), (*(const std::allocator<char>*)(& std::allocator<char>()))))) += "myclass"’
make: *** [all.o] Error 1
Perhaps something like :
CharacterVector classes = out.attr( "class" ) ;
classes.push_back( "myclass" ) ;
out.attr( "class" ) = classes ;
There could be room for a generic append
function.
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