Skip to content

Commit c5ad7ef

Browse files
clear out bugs and cmd check feedback
1 parent 6d082f9 commit c5ad7ef

File tree

5 files changed

+49
-7
lines changed

5 files changed

+49
-7
lines changed

R/canonical.R

+2-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@
2525
#' @name Canonicalize DAGs
2626
node_canonical <- function(.dag, ...) {
2727
.dag <- if_not_tidy_daggity(.dag)
28-
dagitty::canonicalize(pull_dag(.dag))$g %>% tidy_dagitty(...)
28+
dagitty::canonicalize(pull_dag(.dag))$g %>%
29+
tidy_dagitty(..., use_existing_coords = FALSE)
2930
}
3031

3132
#' @rdname canonicalize

R/tidy_dag.R

+14-3
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@
66
#' for details. Alternatively, `"time_ordered"` will use
77
#' `time_ordered_coords()` to algorithmically sort the graph by time.
88
#' @param ... optional arguments passed to `ggraph::create_layout()`
9+
#' @param use_existing_coords (Advanced). Logical. Use the coordinates produced
10+
#' by `dagitty::coordinates(.dagitty)`? If the coordinates are empty,
11+
#' `tidy_dagitty()` will generate a layout. Generally, setting this to `FALSE`
12+
#' is thus only useful when there is a difference in the variables coordinates
13+
#' and the variables in the DAG, as sometimes happens when recompiling a DAG.
914
#'
1015
#' @return a `tidy_dagitty` object
1116
#' @export
@@ -31,7 +36,7 @@
3136
#' geom_dag_text() +
3237
#' geom_dag_edges() +
3338
#' theme_dag()
34-
tidy_dagitty <- function(.dagitty, seed = NULL, layout = "nicely", ...) {
39+
tidy_dagitty <- function(.dagitty, seed = NULL, layout = "nicely", ..., use_existing_coords = TRUE) {
3540
if (!is.null(seed)) set.seed(seed)
3641

3742
if (dagitty::graphType(.dagitty) != "dag") {
@@ -57,7 +62,7 @@ tidy_dagitty <- function(.dagitty, seed = NULL, layout = "nicely", ...) {
5762
generate_layout(
5863
layout = layout,
5964
vertices = names(.dagitty),
60-
coords = dagitty::coordinates(.dagitty),
65+
coords = if (isTRUE(use_existing_coords)) dagitty::coordinates(.dagitty),
6166
...
6267
)
6368

@@ -68,7 +73,9 @@ tidy_dagitty <- function(.dagitty, seed = NULL, layout = "nicely", ...) {
6873
dplyr::distinct(name, x, y) %>%
6974
coords2list()
7075

76+
.labels <- label(.dagitty)
7177
dagitty::coordinates(.dagitty) <- coords
78+
label(.dagitty) <- .labels
7279

7380
new_tidy_dagitty(tidy_dag, .dagitty)
7481
}
@@ -93,6 +100,10 @@ tidy_dagitty <- function(.dagitty, seed = NULL, layout = "nicely", ...) {
93100
#' @param x An object to convert into a `tidy_dagitty`. Currently supports
94101
#' `dagitty` and `data.frame` objects.
95102
#' @inheritParams tidy_dagitty
103+
#' @inheritParams dagify
104+
#' @param saturate Logical. Saturate the DAG such that there is an edge going
105+
#' from every point in the future from a given node? Setting this to `TRUE`
106+
#' will potentially lead to more edges than present in `x`.
96107
#'
97108
#' @return a `tidy_dagitty` object
98109
#' @export
@@ -108,7 +119,7 @@ tidy_dagitty <- function(.dagitty, seed = NULL, layout = "nicely", ...) {
108119
#' # create a saturated, time-ordered DAG
109120
#' as_tidy_dagitty() %>%
110121
#' # remove the edge from `c` to `f`
111-
#' dag_prune("c" = "f")
122+
#' dag_prune(c("c" = "f"))
112123
#'
113124
#' @seealso [tidy_dagitty()], [pull_dag()]
114125
as_tidy_dagitty <- function(x, ...) {

man/as_tidy_dagitty.Rd

+19-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/tidy_dagitty.Rd

+13-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/testthat/test-pull.R

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
test_that("pull_dag and pull_dag_data return the correct objects", {
22
# Create a dagitty object
3-
dag <- dagify(y ~ x + z, x ~ z)
3+
dag <- dagify(y ~ x + z, x ~ z, coords = time_ordered_coords())
44

55
# Create a tidy_dagitty object
66
tidy_dag <- tidy_dagitty(dag, seed = 1234)

0 commit comments

Comments
 (0)