Skip to content

Add integer/double scale_type methods#5168

Merged
teunbrand merged 1 commit intotidyverse:mainfrom
teunbrand:int_dbl_scale_type
Feb 9, 2023
Merged

Add integer/double scale_type methods#5168
teunbrand merged 1 commit intotidyverse:mainfrom
teunbrand:int_dbl_scale_type

Conversation

@teunbrand
Copy link
Copy Markdown
Collaborator

This PR aims to fix #4605.

Briefly, it now has separate integer/double scale_type methods so that classes that inherit from those types also get recognised as continuous scales.

A demo:

dbl <- vctrs::new_vctr(1,  inherit_base_type = TRUE)
int <- vctrs::new_vctr(1L, inherit_base_type = TRUE)

library(ggplot2) # CRAN version

scale_type(dbl)
#> Don't know how to automatically pick scale for object of type
#> <vctrs_vctr/double>. Defaulting to continuous.
#> [1] "continuous"
scale_type(int)
#> Don't know how to automatically pick scale for object of type
#> <vctrs_vctr/integer>. Defaulting to continuous.
#> [1] "continuous"

devtools::load_all("~/packages/ggplot2") # This PR
#> ℹ Loading ggplot2

scale_type(dbl)
#> [1] "continuous"
scale_type(int)
#> [1] "continuous"

Created on 2023-01-31 with reprex v2.0.2

Copy link
Copy Markdown
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 - we should keep numeric in just for safety

@teunbrand teunbrand merged commit 37d9e8c into tidyverse:main Feb 9, 2023
@teunbrand teunbrand deleted the int_dbl_scale_type branch February 9, 2023 18:52
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.

ggplot2 can't determine that Haven labelled integers are discrete

2 participants