Skip to content

fix: support ggplot2 v4.0.0 for ComplexHeatmap plots#205

Open
Copilot wants to merge 29 commits into
mainfrom
copilot/support-ggplot2-v4-0-0
Open

fix: support ggplot2 v4.0.0 for ComplexHeatmap plots#205
Copilot wants to merge 29 commits into
mainfrom
copilot/support-ggplot2-v4-0-0

Conversation

Copilot AI commented May 4, 2026

Copy link
Copy Markdown
Contributor

ggplot2 v4.0.0 breaks correlation heatmap rendering in filter_counts(), normalize_counts(), and batch_correct_counts(), causing Error in plot.window(): ! need finite 'xlim' values.

Root causes & fixes

  • Invalid + ggplot2::labs() on ComplexHeatmap objects (filter.R, normalize.R, batch-correction.R): plot_corr_heatmap() returns a ComplexHeatmap::Heatmap, not a ggplot. ComplexHeatmap's + operator concatenates heatmaps; adding ggplot2::labs() to it produces a corrupted object in ggplot2 4.0.0. These are replaced with a new caption parameter on print_or_save_plot().

  • base::plot() used for ComplexHeatmap in print_or_save_plot() (plots.R): base::plot() (and print()) dispatch incorrectly for Heatmap/HeatmapList objects under ggplot2 4.0.0. Added explicit branches to use ComplexHeatmap::draw() instead.

  • Caption support for ComplexHeatmap (plots.R): Added a caption parameter to print_or_save_plot(). For ComplexHeatmap/HeatmapList objects, the caption is rendered at the bottom of the graphics device using grid::grid.text(). For ggplot objects, ggplot2::labs(caption = caption) is used as before. Callers in filter.R, normalize.R, and batch-correction.R pass the appropriate caption string.

  • Removed ggplot2 version pin (DESCRIPTION, .github/package-versions.txt): The ggplot2 (< 4.0.0) constraint is removed from DESCRIPTION and the any::ggplot2@3.5.2 pin is removed from .github/package-versions.txt.

  • Restored standard CI actions (.github/workflows/R-CMD-check.yaml): Reverted the R-CMD-check and lint jobs from CCBR/actions/install-r-pak@main back to r-lib/actions/setup-r@v2 + r-lib/actions/setup-r-dependencies@v2.

Tests

New and updated tests in tests/testthat/test-plots.R cover:

  • Saving a ComplexHeatmap to disk via print_or_save_plot() without error
  • Saving a ComplexHeatmap with a caption via print_or_save_plot()
  • Saving a ggplot with a caption via print_or_save_plot()
  • Printing a ComplexHeatmap with a caption using withr::with_png() for safe graphics device cleanup

Copilot AI linked an issue May 4, 2026 that may be closed by this pull request
Agent-Logs-Url: https://github.com/CCBR/MOSuite/sessions/1de03834-a603-4a38-a1a3-ce94ecbdf07c

Co-authored-by: kelly-sovacool <17768269+kelly-sovacool@users.noreply.github.com>
Copilot AI changed the title [WIP] Support ggplot2 version 4.0.0 and resolve current errors fix: support ggplot2 v4.0.0 for ComplexHeatmap plots May 4, 2026
Copilot AI requested a review from kelly-sovacool May 4, 2026 17:37
@codecov

codecov Bot commented May 4, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 97.05882% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 79.63%. Comparing base (6c3f164) to head (aa22a8e).

Files with missing lines Patch % Lines
R/plots.R 95.45% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #205      +/-   ##
==========================================
+ Coverage   79.58%   79.63%   +0.04%     
==========================================
  Files          22       22              
  Lines        3375     3398      +23     
==========================================
+ Hits         2686     2706      +20     
- Misses        689      692       +3     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@kelly-sovacool kelly-sovacool left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • The ggplot2 version pin should be removed from the DESCRIPTION file:
    ggplot2 (< 4.0.0),
  • The CI workflows can be changed back to use r-lib/actions/setup-r-dependencies instead of CCBR/actions/install-r-pak:
    - uses: CCBR/actions/install-r-pak@main
    with:
    versions-file: .github/package-versions.txt
    extra-packages: local::.
    needs: dev
    r-version: ${{ matrix.config.r }}
    http-user-agent: ${{ matrix.config.http-user-agent }}

Comment thread R/batch-correction.R
Comment thread NEWS.md Outdated
…ctions, add caption support for ComplexHeatmap

Agent-Logs-Url: https://github.com/CCBR/MOSuite/sessions/89b38b5a-99e6-49bd-b699-4b0f32c262da

Co-authored-by: kelly-sovacool <17768269+kelly-sovacool@users.noreply.github.com>

Copilot AI commented May 4, 2026

Copy link
Copy Markdown
Contributor Author
  • The ggplot2 version pin should be removed from the DESCRIPTION file:
    ggplot2 (< 4.0.0),
  • The CI workflows can be changed b...

Done in commit 9eeb7ac:

  • Removed (< 4.0.0) from ggplot2 in DESCRIPTION
  • Reverted R-CMD-check.yaml (both the R-CMD-check and lint jobs) to use r-lib/actions/setup-r@v2 + r-lib/actions/setup-r-dependencies@v2
  • Cleared the any::ggplot2@3.5.2 pin from .github/package-versions.txt

Copilot AI requested a review from kelly-sovacool May 4, 2026 17:52
@kelly-sovacool kelly-sovacool marked this pull request as ready for review May 4, 2026 17:55

@kelly-sovacool kelly-sovacool left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add or update the tests to ensure the code changes are covered

Copilot AI and others added 2 commits May 4, 2026 17:59
…tmap handling

Agent-Logs-Url: https://github.com/CCBR/MOSuite/sessions/94a2813b-8364-44ec-b39b-3603a8d1fa80

Co-authored-by: kelly-sovacool <17768269+kelly-sovacool@users.noreply.github.com>
Agent-Logs-Url: https://github.com/CCBR/MOSuite/sessions/94a2813b-8364-44ec-b39b-3603a8d1fa80

Co-authored-by: kelly-sovacool <17768269+kelly-sovacool@users.noreply.github.com>

Copilot AI commented May 4, 2026

Copy link
Copy Markdown
Contributor Author

Add or update the tests to ensure the code changes are covered

Added tests in commit d910abe to tests/testthat/test-plots.R:

  • Saves a ComplexHeatmap to disk and asserts the file exists (no caption)
  • Saves a ComplexHeatmap with a caption and asserts the file exists
  • Saves a ggplot with a caption and asserts the file exists
  • Prints a ComplexHeatmap with a caption using withr::with_png() for safe device cleanup

@kelly-sovacool kelly-sovacool left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can anything be done to improve the tests in test-plots.R so they do more than merely check that the code ran without error?

Comment thread tests/testthat/test-plots.R
Comment thread tests/testthat/test-plots.R Outdated
Comment thread tests/testthat/test-plots.R Outdated
…e assertions

Agent-Logs-Url: https://github.com/CCBR/MOSuite/sessions/5a97fa80-deb1-4e4b-92eb-fc16e1d7e547

Co-authored-by: kelly-sovacool <17768269+kelly-sovacool@users.noreply.github.com>

Copilot AI commented May 4, 2026

Copy link
Copy Markdown
Contributor Author

Can anything be done to improve the tests in test-plots.R so they do more than merely check that the code ran without error?

Updated in commit a958630. Each test now also asserts the return value equals the expected file path (expect_equal(result, outfile)) and that the saved file is non-empty (expect_gt(file.size(outfile), 0)).

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates MOSuite plotting to handle ComplexHeatmap correlation heatmaps with ggplot2 4.x while removing the prior ggplot2 version cap.

Changes:

  • Adds caption handling and explicit ComplexHeatmap::draw() support in print_or_save_plot().
  • Updates filter, normalization, and batch-correction workflows to pass heatmap captions without adding ggplot layers to ComplexHeatmap objects.
  • Removes ggplot2 version pins and updates tests, CI setup, metadata, Dockerfiles, and NEWS.

Reviewed changes

Copilot reviewed 16 out of 17 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
R/plots.R Adds caption support and ComplexHeatmap-specific print/save handling.
R/filter.R Updates filtered-count correlation heatmap caption handling.
R/normalize.R Updates normalized-count correlation heatmap caption handling.
R/batch-correction.R Updates batch-corrected correlation heatmap caption handling.
tests/testthat/test-plots.R Adds print/save coverage for ggplot and ComplexHeatmap captions.
tests/testthat/test-plot_volcano_enhanced.R Skips one snapshot test on CI.
DESCRIPTION Bumps package version and removes ggplot2 upper bound.
codemeta.json Syncs package version metadata.
CITATION.cff Syncs package version and ggplot2 dependency metadata.
NEWS.md Adds changelog entry for ggplot2 4.x heatmap support.
man/print_or_save_plot.Rd Updates generated documentation for the new caption parameter.
docker/Dockerfile Removes ggplot2 upper bound in the full image.
docker/Dockerfile_minimal Removes ggplot2 upper bound and adjusts minimal image validation.
.github/workflows/R-CMD-check.yaml Switches R setup/dependency installation back to r-lib actions.
.github/workflows/test-coverage.yaml Switches coverage workflow dependency setup back to r-lib actions.
.github/workflows/pkgdown.yaml Switches pkgdown workflow dependency setup back to r-lib actions.
.github/workflows/auto-format.yml Switches formatting workflow dependency setup back to r-lib actions.
.github/package-versions.txt Removes the ggplot2 3.5.2 pin.
Files not reviewed (1)
  • man/print_or_save_plot.Rd: Language not supported

Comment thread NEWS.md
Comment thread R/plots.R Outdated
…vice

Agent-Logs-Url: https://github.com/CCBR/MOSuite/sessions/cc29b772-a646-4961-a763-0ed9267586bb

Co-authored-by: kelly-sovacool <17768269+kelly-sovacool@users.noreply.github.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 17 out of 18 changed files in this pull request and generated 1 comment.

Files not reviewed (1)
  • man/print_or_save_plot.Rd: Language not supported

Comment thread R/plots.R Outdated
@@ -9,6 +9,9 @@
#' @param plot_obj plot object (e.g. ggplot, ComplexHeatmap...)
#' @param filename name of the output file. will be joined with the `plots_dir` option.
#' @param graphics_device Default: `grDevice::png()`. Only used if the plot is not a ggplot.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in aa22a8e: updated grDevice::png() to grDevices::png() in R/plots.R roxygen text and regenerated man/print_or_save_plot.Rd accordingly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

support ggplot2 v4.0.0

3 participants