Subset igraph by connected components

subset_igraph_components(
  g,
  keep = NULL,
  min_size = 1,
  order_by_size = TRUE,
  ...
)

Arguments

g

igraph object

keep

numeric vector indicating which component or components to keep in the final output. When order_by_size=TRUE, components are ordered by size, from largest to smallest, in that case keep=1 will return only the one largest connected subgraph.

min_size

numeric value indicating the number of nodes required in all connected components returned. This filter is applied after the keep argument.

order_by_size

logical indicating whether the connected components are sorted by size, largest to smallest, and therefore re-numbered. Otherwise, the components are somewhat randomly labeled based upon the output of igraph::components().

...

additional arguments are passed to igraph::components().

Details

This function is intended to help drill down into an igraph object that contains multiple connected components.

By default, it sorts the components from largest number of nodes, to smallest, which helps choose the largest connected component, or subsequent components in size order.

The components can also be filtered to require a minimum number of connected nodes.

At its core, this function is a wrapper to igraph::components() and igraph::subgraph().