Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fallback for validate_subclass() #6119

Merged
merged 7 commits into from
Mar 25, 2025

Conversation

teunbrand
Copy link
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).

R/layer.R Outdated
name <- snakeize(name)
obj <- find_global(name, env = env, mode = "function")
if (is.function(obj)) {
obj <- obj()
Copy link
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
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?

Copy link
Collaborator Author

@teunbrand teunbrand Mar 25, 2025

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
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

Copy link
Member

@thomasp85 thomasp85 left a comment

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
13 checks passed
@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