date_yq(2019, 1) + 1:4` is now possible (closes #5).
Showing 1 of 5 files from the diff.
R/increment.R
changed.
Other files ignored by Codecov
NEWS.md
has changed.
tests/testthat/test_arithmetic.R
has changed.
tests/testthat/test_date_yq.R
has changed.
DESCRIPTION
has changed.
@@ -7,6 +7,14 @@
Loading
7 | 7 | #' An object of the same type as `x` increment by `inc` |
|
8 | 8 | #' @noRd |
|
9 | 9 | increment <- function(x, inc = 1){ |
|
10 | + | assert( |
|
11 | + | is_scalar(inc) || |
|
12 | + | is_equal_length(x, inc) || |
|
13 | + | is_scalar(x), |
|
14 | + | "When adding or subtracting from date_xx objects, both elements must ", |
|
15 | + | "either be of the same length, or one of them must be of length one." |
|
16 | + | ) |
|
17 | + | ||
10 | 18 | UseMethod("increment", x) |
|
11 | 19 | } |
|
12 | 20 |
@@ -14,6 +22,10 @@
Loading
14 | 22 | ||
15 | 23 | ||
16 | 24 | increment.date_yq <- function(x, inc){ |
|
25 | + | if (is_scalar(x) && length(inc) > 1){ |
|
26 | + | x <- rep(x, length(inc)) |
|
27 | + | } |
|
28 | + | ||
17 | 29 | d <- yqs_matrix_from_numeric(x) |
|
18 | 30 | d[, 2] <- d[, 2] + inc |
|
19 | 31 |
@@ -35,6 +47,10 @@
Loading
35 | 47 | ||
36 | 48 | ||
37 | 49 | increment.date_ym <- function(x, inc){ |
|
50 | + | if (is_scalar(x) && length(inc) > 1){ |
|
51 | + | x <- rep(x, length(inc)) |
|
52 | + | } |
|
53 | + | ||
38 | 54 | d <- yms_matrix_from_numeric(x) |
|
39 | 55 | d[, 2] <- d[, 2] + inc |
|
40 | 56 |
@@ -56,6 +72,10 @@
Loading
56 | 72 | ||
57 | 73 | ||
58 | 74 | increment.date_yw <- function(x, inc){ |
|
75 | + | if (is_scalar(x) && length(inc) > 1){ |
|
76 | + | x <- rep(x, length(inc)) |
|
77 | + | } |
|
78 | + | ||
59 | 79 | x <- first_of_isoweek(x) |
|
60 | 80 | as_date_yw(x + 7L * inc) |
|
61 | 81 | } |
@@ -64,5 +84,9 @@
Loading
64 | 84 | ||
65 | 85 | ||
66 | 86 | increment.date_y <- function(x, inc){ |
|
87 | + | if (is_scalar(x) && length(inc) > 1){ |
|
88 | + | x <- rep(x, length(inc)) |
|
89 | + | } |
|
90 | + | ||
67 | 91 | date_y(as.integer(x) + inc) |
|
68 | 92 | } |
Files | Coverage |
---|---|
R | 95.19% |
Project Totals (17 files) | 95.19% |
Sunburst
The inner-most circle is the entire project, moving away from the center are folders then, finally, a single file.
The size and color of each slice is representing the number of statements and the coverage, respectively.
Icicle
The top section represents the entire project. Proceeding with folders and finally individual files.
The size and color of each slice is representing the number of statements and the coverage, respectively.