ggcheck
ggcheck copied to clipboard
Check facets
At a minimum, we want to check for:
- the functions (e.g.
facet_wrapvsfacet_grid) - the variables within the functions (e.g.
~ cylordrv ~ cylornrow = 1)
@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.