Skip to contents

pull_dag() and pull_dag_data() are generic methods to pull components of DAG objects, e.g. tidy_dagitty, such as the dagitty object or the data frame associated with it. These methods are recommended over extracting components manually, e.g. my_dag$data, because the internal structure of these objects may change over time. Similarly, use update_dag() if you want to sync the data back to the DAG object or override it with another DAG; use update_dag_data() to do update the data frame. This is useful with pull_dag_data().

Usage

pull_dag(x, ...)

# S3 method for tidy_dagitty
pull_dag(x, ...)

# S3 method for dagitty
pull_dag(x, ...)

pull_dag_data(x, ...)

# S3 method for tidy_dagitty
pull_dag_data(x, ...)

# S3 method for dagitty
pull_dag_data(x, ...)

update_dag_data(x) <- value

# S3 method for tidy_dagitty
update_dag_data(x) <- value

update_dag(x, ...)

update_dag(x) <- value

# S3 method for tidy_dagitty
update_dag(x, ...)

# S3 method for tidy_dagitty
update_dag(x) <- value

Arguments

x

a tidy_dagitty or dagitty object.

...

For dagitty objects, passed to tidy_dagitty() if needed, otherwise currently unused.

value

a value to set, either a dagitty or data.frame object, depending on the function.

Value

a DAG object, e.g. dagitty, or data frame

Examples


tidy_dagitty_obj <- dagify(y ~ x + z, x ~ z) %>%
  tidy_dagitty()
dag <- pull_dag(tidy_dagitty_obj)
dag_data <- pull_dag_data(tidy_dagitty_obj)

tidy_dagitty_obj %>%
  dplyr::mutate(name = toupper(name)) %>%
  # recreate the DAG component
  update_dag()
#> # A DAG with 3 nodes and 3 edges
#> #
#> # A tibble: 4 × 8
#>   name       x        y direction to      xend     yend circular
#>   <chr>  <dbl>    <dbl> <fct>     <chr>  <dbl>    <dbl> <lgl>   
#> 1 X      0.221  0.985   ->        y      0.329 -0.00828 FALSE   
#> 2 Y      0.329 -0.00828 NA        NA    NA     NA       FALSE   
#> 3 Z     -0.586  0.395   ->        x      0.221  0.985   FALSE   
#> 4 Z     -0.586  0.395   ->        y      0.329 -0.00828 FALSE   

dag_data$label <- paste0(dag_data$name, "(observed)")
update_dag_data(tidy_dagitty_obj) <- dag_data