Skip to content

Commit

Permalink
Override default density method (#5358)
Browse files Browse the repository at this point in the history
  • Loading branch information
teunbrand authored Jul 20, 2023
1 parent 2a7ca74 commit 6e78749
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions tests/testthat/helper-density.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@

# In R devel from 4.3.0 onwards, the density calculation has slightly changed,
# which affects visual snapshots that use a density calculation, like
# `geom_violin()` and `geom_density()`.
# See https://developer.r-project.org/blosxom.cgi/R-devel/NEWS/2023/05/03#n2023-05-03
#
# It has a backwards compatibility argument called 'old.coords' that can be used
# to perform the classic density calculation, which means we can stably use
# visual tests in R devel.
#
# Since that argument is not available in older versions, we have to use the
# following workaround. Here, we conditionally override the default
# density method to use `old.coords = TRUE`.
if ("old.coords" %in% names(formals(stats::density.default))) {
registerS3method(
"density", "default",
function(..., old.coords = TRUE) {
stats::density.default(..., old.coords = old.coords)
}
)
}

0 comments on commit 6e78749

Please sign in to comment.