4.5 dint

While lubridate can handle date & time data in an effective manner, currently it requires the largest unit of a date to be days. This means it does not cover functionality for working with year-quarter, year-month and year-isoweek dates.

In contrast, dint provides a toolkit for these 3 types of date. It stores them in an easily human readable integer format, e.q 20141 for the first quarter of 2014 and so forth. Additionally, it goes hand in hand with lubridate in more ways than one. dint is implemented in base R and comes with zero external dependencies. Even if you don’t work with such special dates directly, dint can still help you at formatting dates, labelling plot axes, or getting first / last days of calendar periods (quarters, months, isoweeks).

dint provides 4 different S3 classes that inherit from date_xx (a superclass for package development purpose).

  • date_yq() for year-quarter dates

  • date_ym for year-month dates

  • date_yw for year-isoweek dates

  • date_y() for storing years. This is for development purpose, and does not provide notable advantage over storing year as integers.

4.5.1 Creation

date_xx vectors can be created using explicit constructors

It is worth mentioning that tsibble also provides similar functions like yearquarter(), yearmonth() and yearweek(). But I think they are generally not flexible in this use case.

as_date_xx coerce other classes (mainly Date, POSIXct(time) and integer) into date_xx objects

4.5.2 Arithmetic and Sequences

All date_xx support addition, subtraction and sequence generation.