Skip to content

Add examples for DateVector and DateTimeVector to Rcpp Gallery #118

@aryoda

Description

@aryoda

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions