In the C++
code for the RcppDateExample.cpp
file:
// [[Rcpp::export]]
List DateExample(DateVector & dv, DatetimeVector & dtv) {
Function formatDate("format.Date");
Function formatDatetime("format.POSIXct");Rprintf("\nIn C++, seeing the following date value\n");
for (int i=0; i<dv.size(); i++) {
Rcout << as<std::string>(formatDate(wrap(dv[i]))) << std::endl;
dv[i] = dv[i] + 7; // shift a week
}
Rprintf("\nIn C++, seeing the following datetime value\n");
for (int i=0; i<dtv.size(); i++) {
Rcout << as<std::string>(formatDatetime(wrap(dtv[i]))) << std::endl;
dtv[i] = dtv[i] + 0.250; // shift 250 millisec
}
// Build result set to be returned as a list to R.
return List::create(Named("date", dv),
Named("datetime", dtv));
}