Skip to content

Use vctrs coercions #914

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

Merged
merged 12 commits into from
Sep 8, 2022
Merged

Use vctrs coercions #914

merged 12 commits into from
Sep 8, 2022

Conversation

hadley
Copy link
Member

@hadley hadley commented Sep 6, 2022

So far have just removed coercions that vctrs doesn't support, which breaks ~15 packages.

Fixes #904

@hadley
Copy link
Member Author

hadley commented Sep 6, 2022

I've now implemented the remaining pieces. See news for details.

The error messages could certainly be improved, but I think that's worth implementing in a separate PR.

@hadley hadley marked this pull request as ready for review September 6, 2022 16:48
@hadley hadley requested a review from lionel- September 6, 2022 16:51
Copy link
Member

@lionel- lionel- left a comment

Choose a reason for hiding this comment

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

We would switch to vec_cast() in a second step right?

I think we may need to provide an edition or a legacy global option to keep supporting existing scripts that these changes will break. Maybe we should keep the existing code as is and provide a vctrs default path?

@hadley
Copy link
Member Author

hadley commented Sep 7, 2022

For now, should deprecate character coercions rather than eliminating them all together.

Comment on lines +78 to +79
if (i == 0)
deprecate_to_char("logical");
Copy link
Member Author

Choose a reason for hiding this comment

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

@lionel- This is a bit of a hack because I want to deprecate aggressively so deprecate_to_char() uses always = TRUE and then I only call it for the first element. There's some small risk that the deprecation message won't get generated if the transformation is not type stable (e.g. map_chr(list("x", 1), identity)) but I think it's worth taking that small risk is return for much simpler code.

@hadley hadley merged commit d2896e2 into main Sep 8, 2022
@hadley hadley deleted the vctrs-coerce branch September 8, 2022 14:29
Comment on lines +49 to +51
* `map_dbl(1.5, identity)` now fails because we believe that silently
truncating doubles to integers is dangerous. But note that
`map_dbl(1, identity)` still works since no numeric precision is lost.
Copy link
Member

Choose a reason for hiding this comment

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

Isn't this map_int() in both examples here?

Copy link
Member Author

Choose a reason for hiding this comment

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

Ooops yes.

deprecate_to_char <- function(type) {
lifecycle::deprecate_warn(
"0.4.0",
I(paste0("Automatical coercion from ", type, " to character")),
Copy link
Member

Choose a reason for hiding this comment

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

Automatic not Automatical?

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.

Match vctrs coercion rules for simple types
3 participants