Skip to content

Commit 8d8a8ce

Browse files
committed
Minor fixes to tests due to changes in R-base
1 parent 16925fe commit 8d8a8ce

File tree

9 files changed

+116
-65
lines changed

9 files changed

+116
-65
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ Type: Package
22
Package: dint
33
Title: A Toolkit for Year-Quarter, Year-Month and Year-Isoweek
44
Dates
5-
Version: 2.1.4
5+
Version: 2.1.5
66
Authors@R:
77
person(given = "Stefan",
88
family = "Fleck",

NEWS.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
1+
# dint 2.1.5
2+
3+
* Minor fixes to tests due to changes in R-base
4+
5+
16
# dint 2.1.4
27

38
* vectors of length 1 are now recycled when adding or subtracting `date_xx`
49
objects, e.g. `date_yq(2019, 1) + 1:4` is now possible (#5).
5-
* `qy` can now handle inputs without seperator between quarter and year
10+
* `qy` can now handle inputs without sepperator between quarter and year
611
(e.g. `myfile42019`)
712
* `as.POSIXlt.date_xx()` and `as.POSIXct.date_xx()` now set UTC timezone by
813
default (for compatibility with `as.POSIXct.Date()` changes in latest R version)

R/scale_date_xx.R

Lines changed: 90 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -123,20 +123,36 @@ scale_date_yq <- function(
123123
limits = NULL,
124124
position = "bottom"
125125
){
126-
ggplot2::continuous_scale(
127-
aesthetics,
128-
scale_name = "date_yq",
129-
name = name,
130-
palette = identity,
131-
labels = labels,
132-
guide = default_guide(),
133-
trans = date_yq_trans,
134-
super = ggplot2::ScaleContinuousDate,
135-
position = position,
136-
limits = limits,
137-
breaks = breaks,
138-
expand = c(0.04, 0)
139-
)
126+
if (utils::packageVersion("ggplot2") < "3.5.0"){
127+
ggplot2::continuous_scale(
128+
aesthetics,
129+
scale_name = "date_yq",
130+
name = name,
131+
palette = identity,
132+
labels = labels,
133+
guide = default_guide(),
134+
trans = date_yq_trans,
135+
super = ggplot2::ScaleContinuousDate,
136+
position = position,
137+
limits = limits,
138+
breaks = breaks,
139+
expand = c(0.04, 0)
140+
)
141+
} else {
142+
ggplot2::continuous_scale(
143+
aesthetics,
144+
name = name,
145+
palette = identity,
146+
labels = labels,
147+
guide = default_guide(),
148+
transform = date_yq_trans,
149+
super = ggplot2::ScaleContinuousDate,
150+
position = position,
151+
limits = limits,
152+
breaks = breaks,
153+
expand = c(0.04, 0)
154+
)
155+
}
140156
}
141157

142158

@@ -196,20 +212,36 @@ scale_date_ym <- function(
196212
limits = NULL,
197213
position = "left"
198214
){
199-
ggplot2::continuous_scale(
200-
aesthetics,
201-
scale_name = "date_ym",
202-
name = name,
203-
breaks = breaks,
204-
palette = identity,
205-
labels = labels,
206-
guide = default_guide(),
207-
trans = date_ym_trans,
208-
super = ggplot2::ScaleContinuousDate,
209-
position = position,
210-
limits = limits,
211-
expand = c(0.04, 0)
212-
)
215+
if (utils::packageVersion("ggplot2") < "3.5.0"){
216+
ggplot2::continuous_scale(
217+
aesthetics,
218+
scale_name = "date_ym",
219+
name = name,
220+
breaks = breaks,
221+
palette = identity,
222+
labels = labels,
223+
guide = default_guide(),
224+
trans = date_ym_trans,
225+
super = ggplot2::ScaleContinuousDate,
226+
position = position,
227+
limits = limits,
228+
expand = c(0.04, 0)
229+
)
230+
} else {
231+
ggplot2::continuous_scale(
232+
aesthetics,
233+
name = name,
234+
breaks = breaks,
235+
palette = identity,
236+
labels = labels,
237+
guide = default_guide(),
238+
transform = date_ym_trans,
239+
super = ggplot2::ScaleContinuousDate,
240+
position = position,
241+
limits = limits,
242+
expand = c(0.04, 0)
243+
)
244+
}
213245
}
214246

215247

@@ -266,20 +298,36 @@ scale_date_yw <- function(
266298
limits = NULL,
267299
position = "bottom"
268300
){
269-
ggplot2::continuous_scale(
270-
aesthetics,
271-
scale_name = "date_yw",
272-
name = name,
273-
breaks = breaks,
274-
palette = identity,
275-
guide = default_guide(),
276-
labels = labels,
277-
trans = date_yw_trans,
278-
super = ggplot2::ScaleContinuousDate,
279-
position = position,
280-
limits = limits,
281-
expand = ggplot2::waiver()
282-
)
301+
if (utils::packageVersion("ggplot2") < "3.5.0"){
302+
ggplot2::continuous_scale(
303+
aesthetics,
304+
scale_name = "date_yw",
305+
name = name,
306+
breaks = breaks,
307+
palette = identity,
308+
guide = default_guide(),
309+
labels = labels,
310+
trans = date_yw_trans,
311+
super = ggplot2::ScaleContinuousDate,
312+
position = position,
313+
limits = limits,
314+
expand = ggplot2::waiver()
315+
)
316+
} else {
317+
ggplot2::continuous_scale(
318+
aesthetics,
319+
name = name,
320+
breaks = breaks,
321+
palette = identity,
322+
guide = default_guide(),
323+
labels = labels,
324+
transform = date_yw_trans,
325+
super = ggplot2::ScaleContinuousDate,
326+
position = position,
327+
limits = limits,
328+
expand = ggplot2::waiver()
329+
)
330+
}
283331
}
284332

285333

README.Rmd

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@ knitr::opts_chunk$set(
1616

1717
[![CRAN status](https://www.r-pkg.org/badges/version/dint)](https://cran.r-project.org/package=dint)
1818
[![lifecycle](https://img.shields.io/badge/lifecycle-stable-brightgreen.svg)](https://lifecycle.r-lib.org/articles/stages.html#stable)
19-
[![Travis build status](https://travis-ci.com/s-fleck/dint.svg?branch=master)](https://travis-ci.org/s-fleck/com)
20-
[![Coverage status](https://codecov.io/gh/s-fleck/dint/branch/master/graph/badge.svg)](https://codecov.io/github/s-fleck/dint?branch=master)
19+
2120

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

README.md

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,6 @@
66
[![CRAN
77
status](https://www.r-pkg.org/badges/version/dint)](https://cran.r-project.org/package=dint)
88
[![lifecycle](https://img.shields.io/badge/lifecycle-stable-brightgreen.svg)](https://lifecycle.r-lib.org/articles/stages.html#stable)
9-
[![Travis build
10-
status](https://travis-ci.com/s-fleck/dint.svg?branch=master)](https://travis-ci.org/s-fleck/com)
11-
[![Coverage
12-
status](https://codecov.io/gh/s-fleck/dint/branch/master/graph/badge.svg)](https://codecov.io/github/s-fleck/dint?branch=master)
139

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

@@ -96,7 +92,7 @@ last_of_quarter(q)
9692
first_of_quarter(q)
9793
#> [1] "2014-10-01"
9894
first_of_month(Sys.Date())
99-
#> [1] "2022-10-01"
95+
#> [1] "2024-11-01"
10096
first_of_isoweek(w)
10197
#> [1] "2016-12-26"
10298
last_of_isoweek(w)

cran-comments.md

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
## Test environments
1+
* Fix failing tests due to changes in R-devel
2+
* Compat with ggplot > 3.5.0
3+
24

3-
* rhub (rhub::check_for_cran())
4-
* winbuilder (R-devel)
55

6-
## re-submission
76

8-
fix moved url in README

tests/testthat/test_date_xx.R

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ test_that("date_xx coercion to POSIXt works", {
4444

4545

4646
test_that("Sys.date_** return the appropriate types", {
47-
is_date_yq(Sys.date_yq())
48-
is_date_ym(Sys.date_ym())
49-
is_date_yw(Sys.date_yw())
47+
expect_true(is_date_yq(Sys.date_yq()))
48+
expect_true(is_date_ym(Sys.date_ym()))
49+
expect_true(is_date_yw(Sys.date_yw()))
5050
})

tests/testthat/test_first_of.R

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -178,27 +178,27 @@ test_that("test first_of_month against lubridate", {
178178
test_that("first_of_isoweek works", {
179179
tdat <- seq(as.Date("2004-12-20"), as.Date("2020-01-06"), by = "7 days")
180180

181-
expect_identical(
181+
expect_equal(
182182
first_of_isoweek(tdat),
183183
tdat
184184
)
185185

186-
expect_identical(
186+
expect_equal(
187187
last_of_isoweek(tdat),
188188
tdat + 6L
189189
)
190190

191-
expect_identical(
191+
expect_equal(
192192
seq(as.Date("2004-01-05"), as.Date("2004-12-20"), by = "7 days"),
193193
first_of_yw(2004, 2:52)
194194
)
195-
expect_identical(
195+
expect_equal(
196196
seq(as.Date("2004-01-11"), as.Date("2004-12-26"), by = "7 days"),
197197
last_of_yw(2004, 2:52)
198198
)
199199

200-
expect_identical(first_of_yw("2004-01-07"), as.Date("2004-01-05"))
201-
expect_identical(last_of_yw("2004-01-07"), as.Date("2004-01-11"))
200+
expect_equal(first_of_yw("2004-01-07"), as.Date("2004-01-05"))
201+
expect_equal(last_of_yw("2004-01-07"), as.Date("2004-01-11"))
202202
})
203203

204204

tests/testthat/test_scale_date_xx.R

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,11 @@ test_that("date_ym_breaks doesnt fail for a variety of inputs", {
101101

102102

103103
test_that("date_ym_trans is reversible", {
104+
105+
if (!requireNamespace("scales", quietly = TRUE)){
106+
skip("test requires scales")
107+
}
108+
104109
x <- seq(date_ym(1950, 1), date_ym(2050, 1))
105110
trn <- date_ym_trans$transform(x)
106111
inv <- date_ym_trans$inverse(trn)

0 commit comments

Comments
 (0)