Skip to content
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

Add forbidden layouts #62

Merged
merged 1 commit into from
Oct 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions R/tidy_dag.R
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#' geom_dag_edges() +
#' theme_dag()
tidy_dagitty <- function(.dagitty, seed = NULL, layout = "nicely", ...) {
check_verboten_layout(layout)

if (!is.null(seed)) set.seed(seed)

Expand Down Expand Up @@ -86,6 +87,12 @@ tidy_dagitty <- function(.dagitty, seed = NULL, layout = "nicely", ...) {
.tdy_dag
}

check_verboten_layout <- function(layout) {
if (layout %in% c("dendogram")) {
stop("Layout type `", layout, "` not supported in ggdag", call. = FALSE)
}
}

#' Test for object class for tidy_dagitty
#'
#' @param x object to be tested
Expand Down
7 changes: 7 additions & 0 deletions tests/testthat/test-tidy_dag.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@ test_that("tidied dags are in good shape", {
expect_true(is.numeric(tidy_dag$data$y))
})

test_that("Forbidden layouts error", {
expect_error(
tidy_dagitty(dagify(y ~ x + z, x ~ z), layout = "dendogram"),
"Layout type `dendogram` not supported in ggdag"
)
})

expect_function_produces_name <- function(tidy_dag, column) {
.df <- tidy_dag$data
expect_true(all(column %in% names(.df)))
Expand Down