Skip to content

Commit 6e78749

Browse files
authored
Override default density method (#5358)
1 parent 2a7ca74 commit 6e78749

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

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)