gs_compute: Apply igraph functions to the graph inside a GraphSpace

View source: R/gspace-accessors.R

gs_computeR Documentation

Apply igraph functions to the graph inside a GraphSpace

Description

gs_compute() runs any igraph function on the graph carried by a GraphSpace, without needing a dedicated ⁠gs_*⁠ wrapper for each one. It extracts the underlying igraph via as.igraph(), applies .f, and returns the result unchanged. This is the read-only lane onto the whole igraph ecosystem: measures such as degree(), betweenness(), coreness(), community detection, and distances all work through this one entry point.

It is deliberately not a graph-modification path. If .f returns a graph (e.g. simplify(), induced_subgraph()), this cannot be reintegrated as a modified graph must go through the graph-modification checks.

Usage

gs_compute(gs, .f, ...)

Arguments

gs

A GraphSpace object.

.f

An igraph function, or the name of one as a string.

...

Further arguments passed on to .f.

Value

Whatever .f returns (typically a named vector, matrix, or summary), aligned to the graph's vertex order.

Examples

library(RGraphSpace)
library(igraph)

# Load a demo igraph
data('gtoy1', package = 'RGraphSpace')

# Create a new GraphSpace object
gs <- GraphSpace(gtoy1)

# Apply igraph functions
gs_compute(gs, igraph::degree)
gs_compute(gs, "betweenness", directed = FALSE)

# Fold a per-vertex result back as a node attribute
gs$degree <- gs_compute(gs, igraph::degree)


RGraphSpace documentation built on Oct. 9, 2026, 9:07 a.m.