Skip to content

Improve handling of abstract S3 classes#692

Merged
hadley merged 3 commits into
mainfrom
abstract-parent
Jun 12, 2026
Merged

Improve handling of abstract S3 classes#692
hadley merged 3 commits into
mainfrom
abstract-parent

Conversation

@hadley

@hadley hadley commented Jun 10, 2026

Copy link
Copy Markdown
Member
  • No longer error when constructing a class that inherits from an abstract S3 class
  • Errors when upcasting to an abstract S3 class
  • New test to confirm that super() works for an abstract S3 class.

No news bullet for the motivating issue since this was a bug introduced in the dev version.

Fixes #686

* No longer error when constructing a class that inherits from an abstract S3 class
* Errors when upcasting to an abstract S3 class
* New test to confirm that `super()` works for an abstract S3 class.

No news bullet for the motivating issue since this was a bug introduced in the dev version.

Fixes #686
@hadley hadley requested a review from t-kalinowski June 10, 2026 12:48
Comment thread R/class.R Outdated
# registered without a constructor (e.g. a marker class like "gg" or "POSIXt").
class_is_abstract <- function(class) {
(is_class(class) && class@abstract) ||
(is_S3_class(class) && class$abstract)

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.

Should we use isTRUE(class$abstract) here, in case the class is missing the $abstract field? This could happen if people are using the new S7 with S7 objects that were constructed with older S7 (i.e., built packages or serialized class defs generated with current release S7).

@hadley hadley Jun 10, 2026

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I think that's pretty low likelihood given the relative rarity of abstract S3 classes. Although I should double check that this fixes the ggplot2 issue.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

isTRUE() doesn't actually help because we need to work with S3 classes created by older S7. And while these are obviously rare in the scheme of things they do occur in ggplot2, hence this issue.

I've added a fallback and verified that this now does actually fix the ggplot2 loading issue.

@hadley hadley merged commit 24d3abc into main Jun 12, 2026
13 checks passed
@hadley hadley deleted the abstract-parent branch June 12, 2026 16:14
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.

ggplot2 fails to install with S7 main

2 participants