Error on geoms other than point(), and when missing geom_point() all together
This commit is contained in:
Родитель
87e51ba953
Коммит
0c2be2275a
|
@ -58,6 +58,8 @@ datamation_sanddance <- function(pipeline, envir = rlang::global_env(), pretty =
|
|||
}
|
||||
|
||||
# Check ggplot2 code for what is supported
|
||||
|
||||
## Facet wrap
|
||||
contains_facet_wrap <- purrr::map_lgl(ggplot2_fittings, function(x) {
|
||||
stringr::str_detect(x, "facet_wrap")
|
||||
}) %>%
|
||||
|
@ -66,6 +68,26 @@ datamation_sanddance <- function(pipeline, envir = rlang::global_env(), pretty =
|
|||
if (contains_facet_wrap) {
|
||||
stop("datamations does not support `facet_wrap()`. Please use `facet_grid()` if you would like to see a faceted datamation.", call. = FALSE)
|
||||
}
|
||||
|
||||
## geom other than geom_point()
|
||||
contains_geom_not_point <- purrr::map_lgl(ggplot2_fittings, function(x) {
|
||||
stringr::str_detect(x, "geom") & !stringr::str_detect(x, "geom_point")
|
||||
}) %>%
|
||||
any()
|
||||
|
||||
if (contains_geom_not_point) {
|
||||
stop("datamations with ggplot2 code only supports `geom_point()`.", call. = FALSE)
|
||||
}
|
||||
|
||||
## No geom_point
|
||||
doesnt_contain_geom_point <- purrr::map_lgl(ggplot2_fittings, function(x) {
|
||||
!stringr::str_detect(x, "geom_point")
|
||||
}) %>%
|
||||
all()
|
||||
|
||||
if (doesnt_contain_geom_point) {
|
||||
stop("datamations using ggplot2 code requires a call to `geom_point()`.", call. = FALSE)
|
||||
}
|
||||
} else {
|
||||
fittings <- full_fittings
|
||||
}
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
library(ggplot2)
|
||||
|
||||
test_that("datamation_sanddance returns a frame for the data, one for each group, and three or four for summarize (three if the summary function is not mean, and four if it is - includes an errorbar frame too)", {
|
||||
pipeline <- "penguins %>% group_by(species)"
|
||||
specs <- datamation_sanddance(pipeline) %>%
|
||||
|
@ -80,6 +82,25 @@ facet_wrap(vars(Degree))" %>%
|
|||
)
|
||||
})
|
||||
|
||||
test_that("datamation_sanddance errors on non-geom_point", {
|
||||
expect_error(
|
||||
"small_salary %>%
|
||||
group_by(Work) %>%
|
||||
summarize(mean_salary = median(Salary)) %>%
|
||||
ggplot() +
|
||||
geom_col(aes(x = Work, y = mean_salary))" %>%
|
||||
datamation_sanddance(),
|
||||
"only supports `geom_point"
|
||||
)
|
||||
})
|
||||
|
||||
test_that("datamation_sanddance requires a call to geom_point", {
|
||||
expect_error("small_salary %>%
|
||||
group_by(Work) %>%
|
||||
summarize(mean_salary = median(Salary)) %>%
|
||||
ggplot(aes(x = Work, y = mean_salary))" %>% datamation_sanddance(), "requires a call to `geom_point")
|
||||
})
|
||||
|
||||
# test_that("specs are generated as expected", {
|
||||
# spec <- "small_salary %>% group_by(Degree) %>% summarize(mean = mean(Salary))" %>%
|
||||
# datamation_sanddance()
|
||||
|
|
Загрузка…
Ссылка в новой задаче