Description Details Author(s) References Examples
Rcpp has the classes Rcpp::Date
, Rcpp::Datetime
,
Rcpp::DateVector
and Rcpp::DatetimeVector
.
In the C++
code for the RcppDateExample.cpp
file:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | // [[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.
List result = List::create(
Named("date", dv),
Named("datetime", dtv)
);
return result ;
}
|
Dominick Samperi wrote the initial versions of Rcpp (and RcppTemplate) during 2005 and 2006. Dirk Eddelbuettel made some additions, and became maintainer in 2008. Dirk Eddelbuettel and Romain Francois have been extending Rcpp since 2009.
Writing R Extensions, available at http:www.r-project.org.
1 2 3 4 5 6 7 8 9 | # set up date and datetime vectors
dvec <- Sys.Date() + -2:2
dtvec <- Sys.time() + (-2:2)*0.5
# call the underlying C++ function
result <- RcppDateExample(dvec, dtvec)
# inspect returned object
result
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.