Skip to content

Define non_missing_aes for GeomCol and GeomBar. Closes #2715. #2719

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 3 commits into from
Jul 9, 2018

Conversation

clauswilke
Copy link
Member

Define non_missing_aes for GeomCol and GeomBar. Closes #2715.

@hadley
Copy link
Member

hadley commented Jun 27, 2018

Could we have a unit test for this?

@clauswilke
Copy link
Member Author

In theory yes, in practice I'm running into a strange issue of not being able to test for warnings that are clearly happening. Will post a reprex later today.

@clauswilke
Copy link
Member Author

Here is the reprex. I have no idea what is happening.

library(ggplot2)
library(testthat)

dat <- data.frame(x = c(1, 2, 3))

bplot <- function(extra = list()) {
  ggplot_build(ggplot(dat, aes(x, x)) + geom_col() + extra)
}

# prints warning at the end
bplot(ylim(0.5, 4))
#> $data
#> $data[[1]]
#>   y x PANEL group ymin ymax xmin xmax colour   fill size linetype alpha
#> 1 1 1     1    -1   NA    1 0.55 1.45     NA grey35  0.5        1    NA
#> 2 2 2     1    -1   NA    2 1.55 2.45     NA grey35  0.5        1    NA
#> 3 3 3     1    -1   NA    3 2.55 3.45     NA grey35  0.5        1    NA
#> 
#> 
#> $layout
#> <ggproto object: Class Layout, gg>
#>     coord: <ggproto object: Class CoordCartesian, Coord, gg>
#>         aspect: function
#>         clip: on
#>         default: TRUE
#>         distance: function
#>         expand: TRUE
#>         is_free: function
#>         is_linear: function
#>         labels: function
#>         limits: list
#>         modify_scales: function
#>         range: function
#>         render_axis_h: function
#>         render_axis_v: function
#>         render_bg: function
#>         render_fg: function
#>         setup_data: function
#>         setup_layout: function
#>         setup_panel_params: function
#>         setup_params: function
#>         transform: function
#>         super:  <ggproto object: Class CoordCartesian, Coord, gg>
#>     coord_params: list
#>     facet: <ggproto object: Class FacetNull, Facet, gg>
#>         compute_layout: function
#>         draw_back: function
#>         draw_front: function
#>         draw_labels: function
#>         draw_panels: function
#>         finish_data: function
#>         init_scales: function
#>         map_data: function
#>         params: list
#>         setup_data: function
#>         setup_params: function
#>         shrink: TRUE
#>         train_scales: function
#>         vars: function
#>         super:  <ggproto object: Class FacetNull, Facet, gg>
#>     facet_params: list
#>     finish_data: function
#>     get_scales: function
#>     layout: data.frame
#>     map_position: function
#>     panel_params: list
#>     panel_scales_x: list
#>     panel_scales_y: list
#>     render: function
#>     render_labels: function
#>     reset_scales: function
#>     setup: function
#>     setup_panel_params: function
#>     train_position: function
#>     xlabel: function
#>     ylabel: function
#>     super:  <ggproto object: Class Layout, gg>
#> 
#> $plot
#> Warning: Removed 3 rows containing missing values (geom_col).

#> 
#> attr(,"class")
#> [1] "ggplot_built"

# doesn't catch the warning
expect_warning(bplot(ylim(0.5, 4)), "Removed 3 rows containing missing values")
#> Error: `bplot(ylim(0.5, 4))` did not produce any warnings.

Created on 2018-06-27 by the reprex package (v0.2.0).

@hadley
Copy link
Member

hadley commented Jun 27, 2018

The warning is only generated when bplot() is printed?

@clauswilke
Copy link
Member Author

Actually, yes, just figured it out. The warning happens at the drawing stage, so just building the plot is not enough to trigger it.

@clauswilke
Copy link
Member Author

Regression tests added.

Copy link
Member

@hadley hadley left a comment

Choose a reason for hiding this comment

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

My only concern is that rendering the plot is slow, so I'm not sure if having 4 tests is worth the added cost to unit test run time.

@clauswilke
Copy link
Member Author

I believe there are some unit tests for which rendering is not needed, because the warning is created before the plot is rendered. I will rework the tests so they render only when absolutely needed.

@clauswilke clauswilke merged commit ba2e7ed into tidyverse:master Jul 9, 2018
@clauswilke clauswilke deleted the issue-2715-geom_col branch July 9, 2018 15:34
@lock
Copy link

lock bot commented Jan 5, 2019

This old issue has been automatically locked. If you believe you have found a related problem, please file a new issue (with reprex) and link to this issue. https://reprex.tidyverse.org/

@lock lock bot locked and limited conversation to collaborators Jan 5, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants