Learn R Programming

RGraphSpace (version 1.5.2)

GraphSpace-subscript: Subscript operators for GraphSpace objects

Description

[ 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.

Usage

# S4 method for GraphSpace,ANY,ANY,ANY
[(x, i, j, ..., drop = TRUE)

# S4 method for GraphSpace [[(x, i, j, ...)

Value

[ returns a GraphSpace object.

[[ returns the content of the named slot.

Arguments

x

A GraphSpace object.

i

A node selection. Accepted forms:

  • A character vector of node names.

  • An integer vector of positional indices into @nodes.

  • A logical vector whose length matches the number of nodes.

If omitted, all nodes are retained.

j

An edge selection. Accepted forms:

  • An integer vector of positional indices into @edges.

  • A logical vector whose length matches the number of edges.

Because [ evaluates its arguments in the calling environment before dispatch, unquoted column names such as name1 == "n1" cannot be used directly. Pre-evaluate the expression against the edge table first (e.g. gs_edges(gs)$name1 == "n1"), or use gs_subset_edges which supports unquoted predicates via data masking. If omitted, all edges are retained (subject to node-filter cascade).

...

Currently unused.

drop

Ignored; accepted for S4 method compatibility only.

Details

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.

See Also

gs_subset_nodes, gs_subset_edges, getGraphSpace, cropGraphSpace

Examples

Run this code
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")

Run the code above in your browser using DataLab