-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Should facet + empty spec be a noop? #3070
Comments
I think the error messages should be better but I don’t think facet_wrap should change itself to facet_null if the input is lacking. |
Why is an error better? I think it makes sense not to error because NULL/empty facets should only occur in programmatic cases. Handling the empty case sensibly makes the layer more composable and generally useful. |
I think this makes sense, considering |
But in I think my major gripe is that this can lead to situation where users mistype the name of the faceting variable and then get this single panel view without any errors or warnings... but @hadley should be the judge of that... |
You should normally get an "object not found" error in the case of an expression, or an "At least one layer must contain all faceting variables" error in the case of a bare symbol. Related issue: #2986 |
Ah - this is purely for |
I don't think my_plot <- function(.data, .mapping, ...) {
facet_vars <- vars(...)
p <- ggplot(.data, .mapping) +
geom_point()
if (length(facet_vars) != 0) {
p <- p + facet_wrap(facet_vars)
}
p
} is too complicated, but of course accepting NULL will be more magical. I just tend to dislike objects changing class (FacetWrap -> FacetNull) based on the input data... ¯\(o_O)/¯ |
I don't think it's changing class. An empty FacetWrap behaves as a FacetNull, which makes sense to me. Just like |
For all intend and purpose it will change class as it will behave just like FacetNull... I'd expect FacetWrap to create panels with strips etc., which will not happen as there is not anything to put in them... I dunno... I'm against, but not vehemently, so if anyone else weighs in in favour I'll concede... |
You know, it's "for compatibility with the classic interface" as the doc says. Now we have |
fair point... |
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/ |
Should these be equivalent to
ggplot(mtcars)
instead of failing?Allowing empty specs would make sense in functions:
Then both of these would work, instead of just the latter:
The text was updated successfully, but these errors were encountered: