ggcheck icon indicating copy to clipboard operation
ggcheck copied to clipboard

Check facets

Open nischalshrestha opened this issue 5 years ago • 1 comments

At a minimum, we want to check for:

  • the functions (e.g. facet_wrap vs facet_grid)
  • the variables within the functions (e.g. ~ cyl or drv ~ cyl or nrow = 1)

nischalshrestha avatar Jan 07 '21 20:01 nischalshrestha

@skaltman built some clever code to check for facets:

get_facet <- function(.result) {
  stringr::str_remove(deparse(.result$facet$params$facets[[1]]), "~")
}

get_facet_params <- function(.result) {
  .result$facet$params
}

ncol <- get_facet_params(.result)$ncol

if (!get_facet(.result) == "plant") {
  fail("Did you remember to facet by `plant` using `facet_wrap()`?")
}

if (is.null(ncol)) {
  fail("I expected you to use the `ncol` argument inside of `facet_wrap()` to match the layout in the example plot.")
}

if (ncol != 2) {
  fail("I expected you to set the number of columns using the `ncol` argument inside of `facet_wrap()`.")
}

We should be able to create similar functions within ggcheck for handling facets.

rossellhayes avatar Nov 17 '21 16:11 rossellhayes