View source: R/gspace-accessors.R
| gs_compute | R Documentation |
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.
gs_compute(gs, .f, ...)
gs |
A |
.f |
An igraph function, or the name of one as a string. |
... |
Further arguments passed on to |
Whatever .f returns (typically a named vector, matrix, or
summary), aligned to the graph's vertex order.
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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.