Skip to main content

Add or remove edges

Source: R/transform.R

Description

add_edges() and remove_edges() return a new graph of the same class with the edges described by ... added or removed, using the operators documented at edge-operators (e.g. B %-->% C, C %-->% D); any isolated-node declarations in ... are ignored. remove_edges() errors if an edge in ... is not present in cg. For programmatic use, pass a spec string via spec instead of ....

Usage

add_edges(cg, ..., spec = NULL)

remove_edges(cg, ..., spec = NULL)

Arguments

cg A graph created with cgraph(), of any class.
... Edge expressions; see edge-operators. Mutually exclusive with spec.
spec Edge specification string, for programmatic use. Mutually exclusive with ....

Value

A cgraph.

Examples

dag <- cgraph(A %-->% B)
add_edges(dag, B %-->% C)
#> DAG with 3 nodes and 2 edges:
#>   nodes: A, B, C
#>   edges:
#>     A --> B, B --> C
remove_edges(dag, A %-->% B)
#> DAG with 2 nodes and 0 edges:
#>   nodes: A, B
#>   edges:
#>     (none)