Repository navigation
Improve facet error messages in animint2dir #285
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
Changes from all commits
6c7f082
df00e16
a4307cd
8abc49c
a38733a
dc26c99
674bbe6
ec81fd5
bab67b9
a9a017f
77a7a35
f8c4216
e63d322
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,79 @@ | ||||||
| acontext("Facet error messages") | ||||||
| missing_var_error <- paste( | ||||||
| "Facet variable not found in data: NonExistentColumn", | ||||||
| "Available columns: Sepal.Length, Sepal.Width, Petal.Length, Petal.Width, Species", | ||||||
| sep = "\n" | ||||||
| ) | ||||||
| missing_var_string_error <- paste( | ||||||
| "Facet variable not found in data: MissingVar", | ||||||
| "Available columns: Sepal.Length, Sepal.Width, Petal.Length, Petal.Width, Species", | ||||||
| sep = "\n" | ||||||
| ) | ||||||
| bad_notation_error <- "Invalid facet_wrap formula (. ~ var). Use facet_wrap(~Species) or facet_wrap(\"Species\")" | ||||||
| test_that("facet_wrap string missing variable gives clear error", { | ||||||
| viz <- list( | ||||||
| scatter = ggplot() + | ||||||
| facet_wrap("MissingVar") + | ||||||
| geom_point(aes(Sepal.Length, Petal.Length), data = iris) | ||||||
| ) | ||||||
| expect_error({ | ||||||
| animint2dir(viz) | ||||||
| }, missing_var_string_error, fixed = TRUE) | ||||||
| }) | ||||||
| test_that("facet_wrap formula with missing variable gives clear error", { | ||||||
| viz <- list( | ||||||
| scatter = ggplot() + | ||||||
| facet_wrap(. ~ NonExistentColumn) + | ||||||
| geom_point(aes(Sepal.Length, Petal.Length), data = iris) | ||||||
| ) | ||||||
| expect_error({ | ||||||
| animint2dir(viz) | ||||||
| }, missing_var_error, fixed = TRUE) | ||||||
| }) | ||||||
| test_that("facet_wrap bad notation when variable exists gives clear error", { | ||||||
| viz <- list( | ||||||
| scatter = ggplot() + | ||||||
| facet_wrap(. ~ Species) + | ||||||
| geom_point(aes(Sepal.Length, Petal.Length), data = iris) | ||||||
| ) | ||||||
| expect_error({ | ||||||
| animint2dir(viz) | ||||||
| }, bad_notation_error, fixed = TRUE) | ||||||
| }) | ||||||
| test_that("facet_grid missing variable gives clear error", { | ||||||
| viz <- list( | ||||||
| scatter = ggplot() + | ||||||
| facet_grid(. ~ MissingVar) + | ||||||
| geom_point(aes(Sepal.Length, Petal.Length), data = iris) | ||||||
| ) | ||||||
| expect_error({ | ||||||
| animint2dir(viz) | ||||||
| }, missing_var_string_error, fixed = TRUE) | ||||||
| }) | ||||||
| test_that("facet_wrap tilde notation works", { | ||||||
| viz <- list( | ||||||
| scatter = ggplot() + | ||||||
| facet_wrap(~Species) + | ||||||
| geom_point(aes(Sepal.Length, Petal.Length), data = iris) | ||||||
| ) | ||||||
| info <- animint2dir(viz, open.browser = FALSE) | ||||||
| expect_true(file.exists(file.path(info$out.dir, "index.html"))) | ||||||
| }) | ||||||
| test_that("facet_wrap string notation works", { | ||||||
| viz <- list( | ||||||
| scatter = ggplot() + | ||||||
| facet_wrap("Species") + | ||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. does this work or error?
Suggested change
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ???
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @tdhock yes Sir it works. facet_wrap(~Species) is valid (same as "Species"). The error is only for facet_wrap(. ~ Species). Covered in the "facet_wrap tilde notation works" test. |
||||||
| geom_point(aes(Sepal.Length, Petal.Length), data = iris) | ||||||
| ) | ||||||
| info <- animint2dir(viz, open.browser = FALSE) | ||||||
| expect_true(file.exists(file.path(info$out.dir, "index.html"))) | ||||||
| }) | ||||||
| test_that("facet_grid formula notation works", { | ||||||
| viz <- list( | ||||||
| scatter = ggplot() + | ||||||
| facet_grid(. ~ Species) + | ||||||
| geom_point(aes(Sepal.Length, Petal.Length), data = iris) | ||||||
| ) | ||||||
| info <- animint2dir(viz, open.browser = FALSE) | ||||||
| expect_true(file.exists(file.path(info$out.dir, "index.html"))) | ||||||
| }) | ||||||
Uh oh!
There was an error while loading. Please reload this page.