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 class 'tidy_dagitty'
pull_dag(x, ...)

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

pull_dag_data(x, ...)

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

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

update_dag_data(x) <- value

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

update_dag(x, ...)

update_dag(x) <- value

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

# S3 method for class '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.535  0.511 ->        y      0.175 -0.188 FALSE   
#> 2 Y      0.175 -0.188 NA        NA    NA     NA     FALSE   
#> 3 Z      0.425  0.776 ->        x     -0.535  0.511 FALSE   
#> 4 Z      0.425  0.776 ->        y      0.175 -0.188 FALSE   

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