rcpp-gallery icon indicating copy to clipboard operation
rcpp-gallery copied to clipboard

Add examples for DateVector and DateTimeVector to Rcpp Gallery

Open aryoda opened this issue 6 years ago • 1 comments

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

aryoda avatar Nov 17 '19 15:11 aryoda

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

eddelbuettel avatar Nov 17 '19 20:11 eddelbuettel