Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# ggplot2 (development version)

* Date(time) scales now throw appropriate errors when `date_breaks`,
`date_minor_breaks` or `date_labels` are not strings (@RodDalBen, #5880)
* The `summary()` method for ggplots is now more terse about facets
(@teunbrand, #5989).
* `guide_bins()`, `guide_colourbar()` and `guide_coloursteps()` gain an `angle`
Expand Down
3 changes: 3 additions & 0 deletions R/scale-date.R
Original file line number Diff line number Diff line change
Expand Up @@ -303,12 +303,15 @@ datetime_scale <- function(aesthetics, transform, trans = deprecated(),
if (is.character(minor_breaks)) minor_breaks <- breaks_width(minor_breaks)

if (!is.waive(date_breaks)) {
check_string(date_breaks)
breaks <- breaks_width(date_breaks)
}
if (!is.waive(date_minor_breaks)) {
check_string(date_minor_breaks)
minor_breaks <- breaks_width(date_minor_breaks)
}
if (!is.waive(date_labels)) {
check_string(date_labels)
labels <- function(self, x) {
tz <- self$timezone %||% "UTC"
label_date(date_labels, tz)(x)
Expand Down
17 changes: 16 additions & 1 deletion tests/testthat/test-scale-date.R
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ test_that("datetime colour scales work", {
expect_equal(range(get_layer_data(p)$colour), c("#132B43", "#56B1F7"))
})

test_that("date(time) scales throw warnings when input is numeric", {
test_that("date(time) scales throw warnings when input is incorrect", {
p <- ggplot(data.frame(x = 1, y = 1), aes(x, y)) + geom_point()

expect_warning(
Expand All @@ -82,4 +82,19 @@ test_that("date(time) scales throw warnings when input is numeric", {
"The value was converted to a <POSIXt/POSIXct> object."
)

expect_error(
ggplot_build(p + scale_x_date(date_breaks = c(11, 12))),
"must be a single string"
)

expect_error(
ggplot_build(p + scale_x_date(date_minor_breaks = c(11, 12))),
"must be a single string"
)

expect_error(
ggplot_build(p + scale_x_date(date_labels = c(11, 12))),
"must be a single string"
)

})
Loading