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

coord_cartesian() should probably throw an error is xlim or ylim is length 1 #5297

Closed
DavisVaughan opened this issue May 5, 2023 · 4 comments
Labels
messages requests for improvements to error, warning, or feedback messages

Comments

@DavisVaughan
Copy link
Member

I accidentally ran this, and was rather confused for awhile until I realized I hadn't supplied an upper limit in xlim:

library(ggplot2)

df <- data.frame(
  x = 1:5,
  y = 2:6
)

ggplot(df, aes(x, y)) +
  geom_line() +
  coord_cartesian(xlim = 2)
#> Error in if (all(is.finite(continuous_range_coord)) && diff(continuous_range_coord) < : missing value where TRUE/FALSE needed

Could coord_cartesian(), or possibly something later on, throw an error if it doesn't get a length 2 xlim / ylim?

@teunbrand
Copy link
Collaborator

Thanks Davis! A similar suggestion was made here: #4894 (comment), so hopefully this PR will fix this.

@DavisVaughan
Copy link
Member Author

DavisVaughan commented May 5, 2023

I don't think is.vector() is a particularly good helper to check for this

is.vector(x) returns TRUE if x is a vector of the specified mode having no attributes other than names.

Meaning that the limits can't be any custom data types (since if a class attribute exists it will return false)

@teunbrand
Copy link
Collaborator

You're right, might be simplified to vctrs::vec_check_size() perhaps.

@teunbrand teunbrand added the messages requests for improvements to error, warning, or feedback messages label May 8, 2023
@teunbrand
Copy link
Collaborator

I'm gonna mark this as completed in #4894.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
messages requests for improvements to error, warning, or feedback messages
Projects
None yet
Development

No branches or pull requests

2 participants