Skip to content

Fallback for validate_subclass() - #6119

Merged
teunbrand merged 7 commits into
tidyverse:mainfrom
teunbrand:check_subclass_fallback
Mar 25, 2025
Merged

teunbrand merged 7 commits into
tidyverse:mainfrom
teunbrand:check_subclass_fallback

Conversation

@teunbrand

Copy link
Copy Markdown
Collaborator

This PR aims to progress #5962 and #3798.

Taking the deprecation of GeomCol (#3798) as an example, we want users to be able to use layer(geom = "col", ...) even after the class is deprecated. This PR ensures that layer(geom = "col") finds the geom_col() constructor and returns the geom field from the resulting layer (even if we remove the GeomCol class).

Comment thread R/layer.R Outdated
name <- snakeize(name)
obj <- find_global(name, env = env, mode = "function")
if (is.function(obj)) {
obj <- obj()

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.

Maybe wrap in try_fetch() and rethrow the error with some additional context. We might end in situations where the constructor can't be called without arguments even though it generally should work

Merge branch 'main' into check_subclass_fallback

# Conflicts:
#	R/layer.R
Comment on lines +28 to +29
`environment()` must be either a string or a <geom> object, not an environment.

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.

This seems like a regression in the error message?

@teunbrand teunbrand Mar 25, 2025 •

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I'd argue the message has become more informative. The message comes from this test:

expect_snapshot_error(validate_subclass(environment(), "geom"))

And we now use caller_arg(x) for messaging, so it'd self-describes the input.

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.

Oh - Ignore my pre-coffee eyes

@thomasp85 thomasp85 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.

LGTM apart from the small comment

@teunbrand teunbrand changed the title Fallback for check_subclass() Fallback for validate_subclass() Mar 25, 2025
@teunbrand
teunbrand merged commit f21a858 into tidyverse:main Mar 25, 2025
@teunbrand
teunbrand deleted the check_subclass_fallback branch March 25, 2025 10:50
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