Skip to content

Conversation

teunbrand
Copy link
Collaborator

This PR aims to fix #6092, but has escalated a bit.

I'd say the main thing is that this PR adds and uses a check_length() function that checks whether the length of a vector is of a particular length or within a range of lengths.
This is then used to check scale limits and replace ad hoc length checks.

Small demo:

devtools::load_all("~/packages/ggplot2")
#> ℹ Loading ggplot2
scale_x_continuous(limits = c("A", "B"))
#> Error in `scale_x_continuous()`:
#> ! `limits` must be a <numeric> vector, not a character vector.
scale_x_continuous(limits = c(1:3))
#> Error in `scale_x_continuous()`:
#> ! `limits` must be a vector of length 2, not length 3.

Created on 2024-09-17 with reprex v2.1.1

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.

Apart from small comment LGTM

@teunbrand teunbrand merged commit 8a4c25a into tidyverse:main Oct 30, 2024
13 checks passed
@teunbrand teunbrand deleted the check_scale_limits branch October 30, 2024 10:04
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.

Checking limits argument in scale_<x|y>_continuous
2 participants