6
6
# ' for details. Alternatively, `"time_ordered"` will use
7
7
# ' `time_ordered_coords()` to algorithmically sort the graph by time.
8
8
# ' @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.
9
14
# '
10
15
# ' @return a `tidy_dagitty` object
11
16
# ' @export
31
36
# ' geom_dag_text() +
32
37
# ' geom_dag_edges() +
33
38
# ' theme_dag()
34
- tidy_dagitty <- function (.dagitty , seed = NULL , layout = " nicely" , ... ) {
39
+ tidy_dagitty <- function (.dagitty , seed = NULL , layout = " nicely" , ... , use_existing_coords = TRUE ) {
35
40
if (! is.null(seed )) set.seed(seed )
36
41
37
42
if (dagitty :: graphType(.dagitty ) != " dag" ) {
@@ -57,7 +62,7 @@ tidy_dagitty <- function(.dagitty, seed = NULL, layout = "nicely", ...) {
57
62
generate_layout(
58
63
layout = layout ,
59
64
vertices = names(.dagitty ),
60
- coords = dagitty :: coordinates(.dagitty ),
65
+ coords = if (isTRUE( use_existing_coords )) dagitty :: coordinates(.dagitty ),
61
66
...
62
67
)
63
68
@@ -68,7 +73,9 @@ tidy_dagitty <- function(.dagitty, seed = NULL, layout = "nicely", ...) {
68
73
dplyr :: distinct(name , x , y ) %> %
69
74
coords2list()
70
75
76
+ .labels <- label(.dagitty )
71
77
dagitty :: coordinates(.dagitty ) <- coords
78
+ label(.dagitty ) <- .labels
72
79
73
80
new_tidy_dagitty(tidy_dag , .dagitty )
74
81
}
@@ -93,6 +100,10 @@ tidy_dagitty <- function(.dagitty, seed = NULL, layout = "nicely", ...) {
93
100
# ' @param x An object to convert into a `tidy_dagitty`. Currently supports
94
101
# ' `dagitty` and `data.frame` objects.
95
102
# ' @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`.
96
107
# '
97
108
# ' @return a `tidy_dagitty` object
98
109
# ' @export
@@ -108,7 +119,7 @@ tidy_dagitty <- function(.dagitty, seed = NULL, layout = "nicely", ...) {
108
119
# ' # create a saturated, time-ordered DAG
109
120
# ' as_tidy_dagitty() %>%
110
121
# ' # remove the edge from `c` to `f`
111
- # ' dag_prune("c" = "f")
122
+ # ' dag_prune(c( "c" = "f") )
112
123
# '
113
124
# ' @seealso [tidy_dagitty()], [pull_dag()]
114
125
as_tidy_dagitty <- function (x , ... ) {
0 commit comments