Skip to content

Should facet + empty spec be a noop? #3070

Closed
@lionel-

Description

@lionel-

Should these be equivalent to ggplot(mtcars) instead of failing?

ggplot(mtcars) + facet_wrap(vars())
#> Error: Can't subset with `[` using an object of class NULL.

ggplot(mtcars) + facet_wrap(NULL)
#> Error: Must specify at least one variable to facet by

Allowing empty specs would make sense in functions:

my_plot <- function(.data, .mapping, ...) {
  ggplot(.data, .mapping) +
    geom_point() +
    facet_wrap(vars(...))
}

Then both of these would work, instead of just the latter:

my_plot(starwars, aes(mass, height / 100))

my_plot(starwars, aes(mass, height / 100), gender)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions