| GraphSpace-subscript | R Documentation |
[ subsets a GraphSpace object along two independent
dimensions: the first index (i) selects nodes; the second (j)
selects edges.
[[ retrieves a single named slot from a
GraphSpace object.
## S4 method for signature 'GraphSpace,ANY,ANY,ANY'
x[i, j, ..., drop = TRUE]
## S4 method for signature 'GraphSpace,ANY,ANY'
x[[i, j, ...]]
x |
A |
i |
A node selection. Accepted forms:
If omitted, all nodes are retained. |
j |
An edge selection. Accepted forms:
Because |
... |
Currently unused. |
drop |
Ignored; accepted for S4 method compatibility only. |
Mental model: unlike a data frame, where [i, j] means rows
and columns of the same table, for GraphSpace the two indices
address the two primary components of the graph: nodes (i) and
edges (j). Neither index subsets columns, they select graph
entities.
Synchronization rules:
x[i, ] — node-induced subgraph. After selecting nodes,
edges are automatically pruned to those whose both endpoints survived.
Normalized coordinates are preserved.
x[, j] — edge selection. The node set is not modified;
no node pruning occurs.
x[i, j] — combined selection. Node filtering is applied
first. Edge index j is resolved against the original
edge table; an edge survives only if it appears in j and
both its endpoints survived node filtering (silent intersection).
Note for [[: the slot accessor is read-only. Use the
dedicated replacement methods (gs_image<-,
gs_fdata<-, gs_vertex_attr<-, etc.) to
modify slot contents.
[ returns a GraphSpace object.
[[ returns the content of the named slot.
gs_subset_nodes, gs_subset_edges,
getGraphSpace, cropGraphSpace
library(RGraphSpace)
library(igraph)
g <- make_star(10, mode = "out")
V(g)$nodeSize <- runif(vcount(g), 1, 10)
E(g)$weight <- runif(ecount(g), 0, 1)
gs <- GraphSpace(g)
gs <- normalizeGraphSpace(gs)
#--- [ examples ---
# Node-induced subgraph: keep named nodes, prune dangling edges
gs[c("n1", "n2", "n3"), ]
# Node-induced subgraph by integer position
gs[1:4, ]
# Node-induced subgraph by pre-evaluated logical mask
gs[gs$nodeSize > 5, ]
# Edge selection only: keep all nodes
gs[, 1:3]
gs[, gs_edges(gs)$weight > 0.5]
# Edge selection by endpoint: 'name1' and 'name2' must be pre-evaluated
# when using [, because [ evaluates j in the calling environment.
# Use gs_subset_edges() for unquoted predicate expressions instead.
gs[, gs_edges(gs)$name1 == "n1"]
gs[, gs_edges(gs)$name1 == "n1" & gs_edges(gs)$name2 == "n2"]
gs[, quote(name1 == "n1" & name2 == "n2")]
# Combined: node filter first, then edge intersection
gs[c("n1", "n2", "n3"), gs_edges(gs)$weight > 0.5]
gs[c("n1", "n2", "n3"), gs_edges(gs)$name1 == "n1"]
#--- [[ examples ---
gs[["nodes"]] # same as getGraphSpace(gs, "nodes")
gs[["edges"]] # same as getGraphSpace(gs, "edges")
gs[["graph"]] # same as getGraphSpace(gs, "graph")
gs[["fdata"]] # same as getGraphSpace(gs, "fdata")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.