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

Add support for integer64 variable types #2377

Open
edgararuiz-zz opened this issue Dec 21, 2017 · 5 comments
Open

Add support for integer64 variable types #2377

edgararuiz-zz opened this issue Dec 21, 2017 · 5 comments
Labels
feature scales 🐍

Comments

@edgararuiz-zz
Copy link

edgararuiz-zz commented Dec 21, 2017

Results collected from databases can, including aggregations, could return an integer64 variable type which does not seem to be supported by aes(). The workaround is to coerce as.numeric() prior to plotting.

Code that collects the data:

> by_month <- flights %>%
+     group_by(month) %>%
+     tally() %>%
+     collect() 
> 
> head(by_month)
# A tibble: 6 x 2
  month               n
  <dbl> <S3: integer64>
1    10          556205
2     4          598126
3    12          544958
4     5          606293
5     2          569236
6     7          627931

The plot that is attempted followed by the error's text:

library(ggplot2)

ggplot(by_month) +
  geom_line(aes(x = month, y = n)) 

Don't know how to automatically pick scale for object of type integer64. Defaulting to continuous.

@hadley

This comment has been minimized.

@edgararuiz-zz

This comment has been minimized.

@hadley
Copy link
Member

hadley commented Jun 18, 2019

Slightly more minimal reprex:

library(ggplot2)  

df <- data.frame(x = bit64::as.integer64(1:10))
ggplot(df) + geom_histogram(aes(x))
#> Don't know how to automatically pick scale for object of type integer64. Defaulting to continuous.
#> `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
#> Warning: Removed 10 rows containing non-finite values (stat_bin).

Created on 2019-06-18 by the reprex package (v0.2.1.9000)

Fixing this will probably happen naturally when we start using vctrs in ggplot2.

@paleolimbot
Copy link
Member

paleolimbot commented Jul 7, 2019

Getting ggplot2 to know that the scale for integer64 objects should be continuous is a quick fix:

scale_type.integer64 <- function(x) "continuous" 

However the current holdup is that scale expansion uses ifelse(), which incorrectly type converts integer64 objects. dplyr::if_else() is too strict, however, as it fails when true and false are integer and numeric (which happens often). If this is still worth fixing, the solution would be to replace these two lines:

limits <- ifelse(is.na(coord_limits), limits, coord_limits)

continuous_range <- ifelse(is.finite(final_scale_limits), final_scale_limits, limits)

...with an improved (probably vctrs-powered) ifelse().

@paleolimbot
Copy link
Member

paleolimbot commented Jul 7, 2019

A reprex for future consideration:

library(ggplot2)
scale_type.integer64 <- function(x) "continuous" 

df <- data.frame(x = bit64::as.integer64(1:10))
ggplot(df) + geom_histogram(aes(x))
#> `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
#> Warning: Computation failed in `stat_bin()`:
#> `binwidth` must be positive

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature scales 🐍
Projects
None yet
Development

No branches or pull requests

3 participants