RcppCore / rcpp-gallery

Source code for the Rcpp Gallery website
http://gallery.rcpp.org
Other
69 stars 71 forks source link

Add examples for DateVector and DateTimeVector to Rcpp Gallery #118

Open aryoda opened 5 years ago

aryoda commented 5 years ago

Motivation

It is not obvious how to instantiate DateVector and DatetimeVector using Rcpp in C++ code. Eg. this does not work:

DateVector d = DateVector::create("2010-12-31", "2011-01-01", "2011-05-29");

Currently there is only one article available which mainly focuses on how to work with non-vectorized Dates and Datetimes or using an existing DatetimeVector passed to the example function: https://gallery.rcpp.org/articles/parsing-datetimes/

Request

Add a new article (or modify the existing article) to show examples how to instantiate DateVector and DatetimeVector.

Example code snippets to be included:

// assumes an origin as base for counting the days (risky)
DateVector d = DateVector::create(14974, 14975, 15123);

// uses constructors (shows different ways to create the date elements)
DateVector d = DateVector::create(Date("2010-12-31"), Date("01.01.2011", "%d.%m.%Y"), Date(2011, 05, 29));

References

Rcpp for everyone: Ch 16 - Dates SO question on how to create a new DateVector from dates as strings

eddelbuettel commented 5 years ago

Maybe the easiest solution might be an update to the parsing-datetimes piece?