Skip to contents

Get ancestors of nodes in a caugi

Usage

ancestors(
  cg,
  nodes = NULL,
  index = NULL,
  open = caugi_options("use_open_graph_definition")
)

Arguments

cg

A caugi object.

nodes

A character vector of node names.

index

A vector of node indexes.

open

Boolean. Determines how the graph is interpreted when retrieving ancestors. Default is taken from caugi_options("use_open_graph_definition"), which by default is TRUE.

Value

Either a character vector of node names (if a single node is requested) or a list of character vectors (if multiple nodes are requested).

Examples

cg <- caugi(
  A %-->% B,
  B %-->% C,
  class = "DAG"
)
ancestors(cg, "A") # NULL
#> NULL
ancestors(cg, "A", open = FALSE) # A
#> [1] "A"
ancestors(cg, index = 2) # "A"
#> [1] "A"
ancestors(cg, "B") # "A"
#> [1] "A"
ancestors(cg, c("B", "C"))
#> $B
#> [1] "A"
#> 
#> $C
#> [1] "A" "B"
#> 
#> $B
#> [1] "A"
#>
#> $C
#> [1] "A" "B"