Skip to content

Declare compatibility names in the S7 class hierarchy - #6915

Merged
teunbrand merged 5 commits into
tidyverse:mainfrom
t-kalinowski:fix/s7-declared-compatibility-20261014
Oct 20, 2026
Merged

teunbrand merged 5 commits into
tidyverse:mainfrom
t-kalinowski:fix/s7-declared-compatibility-20261014

Conversation

@t-kalinowski

Copy link
Copy Markdown
Contributor

Declare ggplot, ggplot_built, uneval, and the four legacy element names in the S7 class hierarchy. Subclasses then inherit these compatibility names, which are currently added only by ggplot2's constructors.

For example, a plot subclass now inherits ggplot:

library(ggplot2)
PlotChild <- S7::new_class(name = "PlotChild", parent = class_ggplot)
inherits(PlotChild(), "ggplot")
# [1] TRUE

Plot and element classes use unnamespaced abstract S7 parents; mappings declare their existing S3 class vector. The trailing gg and element assignments remain to preserve class order and method dispatch.

Use unnamespaced abstract S7 ancestors for plot and legacy element aliases
and declare the existing mapping S3 classes. Preserve trailing marker class
order so S7 operator dispatch continues to precede legacy fallbacks.
Comment thread tests/testthat/test-theme-elements.R Outdated
expect_s7_class(child, ElementChild)
expect_s7_class(child, element)
expect_s3_class(child, parent@name)
expect_identical(class(child)[-1], setdiff(class(object), "element"))

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Removed this check since S3 'element' class is now declared in S7 'ggplot2::element' class. It wasn't important that the S3 element class came last IIRC.

@teunbrand
teunbrand force-pushed the fix/s7-declared-compatibility-20261014 branch from 0a888d0 to 4c73178 Compare October 20, 2026 14:22

@teunbrand teunbrand left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM, thanks! I've lightly edited a bit, mostly for clarity

@teunbrand
teunbrand merged commit b638d65 into tidyverse:main Oct 20, 2026
21 of 22 checks passed
teunbrand added a commit that referenced this pull request Oct 21, 2026
* Declare individual compatibility aliases in S7 inheritance

Use unnamespaced abstract S7 ancestors for plot and legacy element aliases
and declare the existing mapping S3 classes. Preserve trailing marker class
order so S7 operator dispatch continues to precede legacy fallbacks.

* Use available S7 package lifecycle hooks

* Keep S7 hierarchy preview separate from lifecycle hooks

* Use helper function for legacy class names

* Drop NEWS.md entry to avoid conflicts with main

---------

Co-authored-by: Teun van den Brand <tahvdbrand@gmail.com>
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.

2 participants