tidyverse/ggplot2

`stat_ellipse()` in ggplot2 4.0.0 breaks `R CMD check` tests

Closed this issue · 4 comments

I found a problem with stat_ellipse() in ggplot2 4.0.0 that causes R CMD check to fail when running tests that use stat_ellipse(). This issue does not occur in ggplot2 3.5.2 and earlier versions.

Reprex

Install ggplot2 4.0.0 RC and create a minimal package:

devtools::install_github("tidyverse/ggplot2@rc/4.0.0")
usethis::create_package("zzz")

In the new package, add dependencies and create a function:

usethis::use_package("ggplot2")
usethis::use_package("vdiffr", type = "Suggests")
usethis::use_r("f")

Add a function that uses stat_ellipse():

f <- function () {
  ggplot2::ggplot(faithful, ggplot2::aes(waiting, eruptions)) +
    ggplot2::geom_point() +
    ggplot2::stat_ellipse()
}

Add a snapshot test:

usethis::use_testthat()
usethis::use_test("f")
testthat::test_that("stat_ellipse works", {
  x <- f()
  vdiffr::expect_doppelganger("call stat_ellipse", x)
})

Run tests to generate the snapshot:

devtools::test()

Run R CMD check --as-cran:

R CMD build zzz
R CMD check zzz_0.0.0.9000.tar.gz --as-cran

The check fails with:

* checking tests ...
  Running ‘testthat.R’
 ERROR
Running the tests in ‘tests/testthat.R’ failed.
Last 13 lines of output:
   1.  │           └─ggplot2 (local) f(l = layers[[i]], d = data[[i]])
   2.  │             └─l$compute_statistic(d, layout)
   3.  │               └─ggplot2 (local) compute_statistic(..., self = self)
   4.  │                 └─self$stat$setup_params(data, self$stat_params)
   5.  │                   └─ggplot2 (local) setup_params(...)
   6.  │                     └─rlang::check_installed("MASS", "for calculating ellipses with `type = \"t\"`.")
   7.  │                       └─base::stop(cnd)
   8.  └─rlang (local) `<fn>`(`<S3: rlib_error_package_not_found>`)
   9.    └─handlers[[1L]](cnd)
   10.     └─cli::cli_abort(...)
   11.       └─rlang::abort(...)

  [ FAIL 1 | WARN 0 | SKIP 0 | PASS 0 ]
  Error: Test failures
  Execution halted

Thanks for the report! This is because we changed the MASS dependency from the Imports field to the Suggests field. If packages rely on stat_ellipse() or stat_density_2d(), they'd need to declare their dependency on MASS via Imports/Suggests as well.

Ah! Simple fix...I guess also a simple fix for gMCPLite???

I don't recall seeing gMCPLite in the list of reverse dependencies negatively affected per CRAN

Great, thanks @teunbrand for the explanation. gsDesign 3.7.0 is now on CRAN and should unblock ggplot2 4.0.0. gMCPLite already has MASS in Imports so that's probably the reason it was not triggered there.