-
Notifications
You must be signed in to change notification settings - Fork 3
/
README.Rmd
100 lines (69 loc) · 2.04 KB
/
README.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
---
output: github_document
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r setup, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
```
# dint
[![CRAN status](https://www.r-pkg.org/badges/version/dint)](https://cran.r-project.org/package=dint)
[![lifecycle](https://img.shields.io/badge/lifecycle-stable-brightgreen.svg)](https://lifecycle.r-lib.org/articles/stages.html#stable)
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](https://CRAN.R-project.org/package=dint/vignettes/dint.html)
or the [documentation](https://s-fleck.github.io/dint/)
## 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:
```{r cran-installation, eval = FALSE}
install.packages("dint")
```
Or install the development version from GitHub with:
```{r gh-installation, eval = FALSE}
# install.packages("devtools")
devtools::install_github("s-fleck/dint")
```
## Example
```{r 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)
```