knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  fig.path = "man/figures/README-",
  out.width = "100%"
)

dint

CRAN status lifecycle

A Toolkit for Year-Quarter, Year-Month and Year-Isoweek Dates

S3 classes and methods to create and work with year-quarter and year-month vectors. Basic arithmetic operations (such as adding and subtracting) are supported, as well as formatting and converting to and from standard R Date types. For more info please refer to the package vignette or the documentation

Dependencies

dint is implemented strictly in base R and will always stay free of hard dependencies. The optional dependencies of dint are just there to facilitate interoperability these packages if you are already using them; for example by providing ggplot2 scales.

Installation

Install the release version of dint from CRAN:

install.packages("dint")

Or install the development version from GitHub with:

# install.packages("devtools")
devtools::install_github("s-fleck/dint")

Example

library(dint)

# creation
q <- date_yq(2014, 4)
m <- as_date_ym(201412)
w <- as_date_yw(as.Date("2017-01-01"))

# printing
print(q)
print(m)
print(w)  # isoweeks do not follow calendar years!

# arithmetic operations
# quarters
q
q + 1
seq(q -2, q + 2)


# months
m
m + 1
seq(m -2, m + 2)


# formatting
format(q)
format(q, "%Y.%q")
format(q, "%y.%q")
format(m)


# get start and end of period
last_of_quarter(q)
first_of_quarter(q)
first_of_month(Sys.Date())
first_of_isoweek(w)
last_of_isoweek(w)


s-fleck/dint documentation built on Nov. 22, 2024, 9:26 a.m.