simplify_igraph_network: Simplify an igraph network such that consecutive linear edges...

View source: R/simplify_igraph_network.R

simplify_igraph_networkR Documentation

Simplify an igraph network such that consecutive linear edges are removed

Description

  • Nodes with degree 2 (or indegree 1 and outdegree 1) are removed: A -> B -> C becomes A -> C

  • Cycles contain at least 3 nodes, ie. A -> B -> A becomes A -> B -> C -> A

  • Loops are converted to a cycle, unless allow_self_loops = TRUE

  • Duplicated edges are removed, unless allow_duplcated_edges = FALSE

Usage

simplify_igraph_network(
  gr,
  allow_duplicated_edges = TRUE,
  allow_self_loops = TRUE,
  force_keep = NULL,
  edge_points = NULL
)

Arguments

gr

An igraph object, see igraph::graph()

allow_duplicated_edges

Whether or not to allow duplicated edges between nodes.

allow_self_loops

Whether or not to allow self loops.

force_keep

Nodes that will not be removed under any condition

edge_points

Points that are on edges

Value

An igraph object, or a list with an igraph object and a data frame with edge points

Examples

net <- data.frame(
  from = 1:2,
  to = 2:3,
  length = 1,
  directed = TRUE,
  stringsAsFactors = F
)
gr <- igraph::graph_from_data_frame(net)
simplify_igraph_network(gr)

net <- data.frame(
  from = c(1, 2, 3, 1),
   to = c(2, 3, 1, 4),
    length = 1,
    directed = TRUE,
    stringsAsFactors = F
)
gr <- igraph::graph_from_data_frame(net)
simplify_igraph_network(gr)

net <- data.frame(
  from = c(1, 2, 3, 4),
   to = c(2, 3, 1, 5),
    length = 1,
    directed = TRUE,
    stringsAsFactors = F
)
gr <- igraph::graph_from_data_frame(net)
simplify_igraph_network(gr)

dynwrap documentation built on July 26, 2023, 5:15 p.m.