Skip to contents

Add, remove, or and set nodes or edges to / from a caugi_graph object. Edges can be specified using expressions with the infix operators. Alternatively, the edges to be added are specified using the from, edge, and to arguments.

Usage

add_edges(cg, ..., from = NULL, edge = NULL, to = NULL)

remove_edges(cg, ..., from = NULL, edge = NULL, to = NULL)

set_edges(cg, ..., from = NULL, edge = NULL, to = NULL)

add_nodes(cg, ..., name = NULL)

remove_nodes(cg, ..., name = NULL)

Arguments

cg

A caugi_graph object.

...

Expressions specifying edges to add using the infix operators, or nodes to add using unquoted names, vectors via c(), or + composition.

from

Character vector of source node names. Default is NULL.

edge

Character vector of edge types. Default is NULL.

to

Character vector of target node names. Default is NULL.

name

Character vector of node names. Default is NULL.

Value

The updated caugi_graph.

Details

Caugi graph verbs

Functions

  • add_edges(): Add edges.

  • remove_edges(): Remove edges.

  • set_edges(): Set edge type for given pair(s).

  • add_nodes(): Add nodes.

  • remove_nodes(): Remove nodes.

See also

Other verbs: build()

Examples

# initialize empty graph and build slowly
cg <- caugi_graph(class = "PDAG")

cg <- cg |>
  add_nodes(c("A", "B", "C", "D", "E")) |> # A, B, C, D, E
  add_edges(A %-->% B %-->% C) |> # A --> B --> C, D, E
  set_edges(B %---% C) # A --> B --- C, D, E

cg <- remove_edges(cg, B %---% C) |> # A --> B, C, D, E
  remove_nodes(c("C", "D", "E")) # A --> B

# verbs do not build the Rust backend
cg@built # FALSE
#> [1] FALSE
build(cg)
#> # A tibble: 2 × 1
#>   name 
#>   <chr>
#> 1 A    
#> 2 B    
#> # A tibble: 1 × 3
#>   from  edge  to   
#>   <chr> <chr> <chr>
#> 1 A     -->   B    
cg@built # TRUE
#> [1] TRUE