run_infomap: Interface R and igraph with Infomap (external binary)

View source: R/modularity.R

run_infomapR Documentation

Interface R and igraph with Infomap (external binary)

Description

This function exports an igraph network to Infomap's required format, runs Infomap, and imports the detected communities back into R as an igraph-compatible cluster object. It requires the installation of infomap in the system from https://www.mapequation.org/infomap/#Install if the network has the weight attribute, it will be used as the weight of the edges.

Usage

run_infomap(
  graph,
  infomap_path = "infomap",
  output_dir = tempdir(),
  directed = TRUE,
  two_level = TRUE,
  seed = 123
)

Arguments

graph

An igraph object.

infomap_path

Path to the Infomap binary (default assumes it's in system PATH).

output_dir

Temporary directory for Infomap results.

directed

Boolean: Treat the network as directed (default TRUE).

two_level

Boolean: Use two-level Infomap (default TRUE).

seed

Numeric: Random seed for Infomap (default 123).

Value

An igraph community object similar to igraph's cluster_infomap.

Examples

# Example with the intermediate files in actual folder
py_infomap <- run_infomap(netData[[1]],output_dir=".", weighted = FALSE)

membership(py_infomap)
modularity(py_infomap)


lsaravia/EcoNetwork documentation built on April 5, 2025, 1:51 p.m.