Learn R Programming

dint

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)
#> [1] "2014-Q4"
print(m)
#> [1] "2014-M12"
print(w)  # isoweeks do not follow calendar years!
#> [1] "2016-W52"

# arithmetic operations
# quarters
q
#> [1] "2014-Q4"
q + 1
#> [1] "2015-Q1"
seq(q -2, q + 2)
#> [1] "2014-Q2" "2014-Q3" "2014-Q4" "2015-Q1" "2015-Q2"


# months
m
#> [1] "2014-M12"
m + 1
#> [1] "2015-M01"
seq(m -2, m + 2)
#> [1] "2014-M10" "2014-M11" "2014-M12" "2015-M01" "2015-M02"


# formatting
format(q)
#> [1] "2014-Q4"
format(q, "%Y.%q")
#> [1] "2014.4"
format(q, "%y.%q")
#> [1] "14.4"
format(m)
#> [1] "2014-M12"


# get start and end of period
last_of_quarter(q)
#> [1] "2014-12-31"
first_of_quarter(q)
#> [1] "2014-10-01"
first_of_month(Sys.Date())
#> [1] "2022-10-01"
first_of_isoweek(w)
#> [1] "2016-12-26"
last_of_isoweek(w)
#> [1] "2017-01-01"

Copy Link

Version

Install

install.packages('dint')

Monthly Downloads

1,161

Version

2.1.4

License

MIT + file LICENSE

Issues

Pull Requests

Stars

Forks

Maintainer

Stefan Fleck

Last Published

October 17th, 2022

Functions in dint (2.1.4)

first_of_isoweek

Get First / Last Day of an Isoweek
first_of_month

Get First / Last Day of a Month
dint-package

dint: A Toolkit for Year-Quarter, Year-Month and Year-Isoweek Dates
date_ym

A Simple S3-Class for Year-Month Dates
first_of_quarter

Get First / Last Day of a Quarter
first_of_year

Get First / Last Day of a Year
date_yq

A Simple S3-Class for Year-Quarter Dates
first_of_isoyear

Get First / Last Day of the First and Last Isoweek of a Year
date_y

A Simple S3-Class for Years
date_yw

A Simple S3-Class for Year-Isoweek Dates
rep.date_xx

Replicate Elements of date_xx Vectors
format_yw

Coerce and Format to Year-Isoweek Strings
print.date_xx

Print a date_xx Object
format_yq

Coerce and Format to Year-Quarter Strings
first_of_yq

Get First or Last Day of Quarter From Year and Quarter
[.date_xx

Extract or Replace Elements of a date_xx
year.date_xx

Get Year, Quarter or Month (lubridate Compatibility)
%y+%

Add/Subtract Year
get_year

Get Year, Quarter, Month or Isoweek
is_quarter_bounds

Useful Predicates for Dates
scale_date_xx

ggplot2 Scales For date_xx Objects
format_ym

Coerce and Format to Year-Month Strings
yq

Parse Dates With Year and Quarter Components
format_date_xx

Format a date_xx
round.date_yq

Rounding of date_xx
Ops.date_xx

Comparison Operators for date_xx
as_yearqtr

Coerce to zoo yearqtr objects
date_xx_breaks

Pretty Breaks For date_xx Vectors
Summary.date_xx

Maxima and Minima for date_xx
date_xx_arithmetic_disabled

Arithmetic Operations Disabled for date_xx
date_xx

A Superclass For All dint Objects
c.date_xx

Concatenate date_xx Objects
date_xx_sequences

date_xx Sequence Generation
as.Date.date_xx

Coerce dint Objects to Base R Date Types
date_xx_arithmetic

date_xx Arithmetic Operations