Skip to content

Commit f4b2dab

Browse files
authored
Fix version comparison (#5376)
* Reimplement #5367 * Override default density method
1 parent 5355937 commit f4b2dab

File tree

3 files changed

+28
-2
lines changed

3 files changed

+28
-2
lines changed

NEWS.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
# ggplot2 3.4.3
2+
3+
This hotfix release addresses a version comparison change in r-devel. There are
4+
no user-facing or breaking changes.
5+
16
# ggplot2 3.4.2
27
This is a hotfix release anticipating changes in r-devel, but folds in upkeep
38
changes and a few bug fixes as well.

R/backports.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Backport fix from R 3.3:
22
# https://github.com/wch/r-source/commit/4efc81c98d262f93de9e7911aaa910f5c63cd00f
3-
if (getRversion() < 3.3) {
3+
if (getRversion() < "3.3") {
44
absolute.units <- getFromNamespace("absolute.units", "grid")
55
absolute.units.unit <- getFromNamespace("absolute.units.unit", "grid")
66
absolute.units.unit.list <- getFromNamespace("absolute.units.unit.list", "grid")
@@ -18,6 +18,6 @@ if (getRversion() < 3.3) {
1818
on_load(backport_unit_methods())
1919

2020
# isFALSE() is available on R (>=3.5)
21-
if (getRversion() < 3.5) {
21+
if (getRversion() < "3.5") {
2222
isFALSE <- function(x) is.logical(x) && length(x) == 1L && !is.na(x) && !x
2323
}

tests/testthat/helper-density.R

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
2+
# In R devel from 4.3.0 onwards, the density calculation has slightly changed,
3+
# which affects visual snapshots that use a density calculation, like
4+
# `geom_violin()` and `geom_density()`.
5+
# See https://developer.r-project.org/blosxom.cgi/R-devel/NEWS/2023/05/03#n2023-05-03
6+
#
7+
# It has a backwards compatibility argument called 'old.coords' that can be used
8+
# to perform the classic density calculation, which means we can stably use
9+
# visual tests in R devel.
10+
#
11+
# Since that argument is not available in older versions, we have to use the
12+
# following workaround. Here, we conditionally override the default
13+
# density method to use `old.coords = TRUE`.
14+
if ("old.coords" %in% names(formals(stats::density.default))) {
15+
registerS3method(
16+
"density", "default",
17+
function(..., old.coords = TRUE) {
18+
stats::density.default(..., old.coords = old.coords)
19+
}
20+
)
21+
}

0 commit comments

Comments
 (0)