gs_add_edges: Add edges to a GraphSpace object

gs_add_edgesR Documentation

Add edges to a GraphSpace object

Description

gs_add_edges() and gs_add_edges<- add one or more edges to a GraphSpace object. Both endpoints of every new edge must already exist in the node set. The @graph, @edges, and all derived edge quantities are updated consistently; the node set and the normalized coordinate state are not affected.

gs_add_edges(x, value) is the pipe-friendly functional form and returns the modified object. gs_add_edges(x) <- value is the in-place replacement form and modifies x by reference in the calling environment. Both forms are equivalent.

Usage

## S4 method for signature 'GraphSpace'
gs_add_edges(x, value, ...)

## S4 replacement method for signature 'GraphSpace'
gs_add_edges(x) <- value

Arguments

x

A GraphSpace object.

value

Edges to add, given as a data frame or a vertex sequence:

  • Data frame: at least two columns identifying the edge endpoints, using one of two accepted naming conventions:

    • from / to — the tidygraph / igraph convention.

    • name1 / name2 — the @edges slot convention, useful when constructing value directly from gs_edges().

    If both conventions are present, from/to takes priority. Any additional columns are treated as edge attributes and passed through to @edges. Standard visual attributes (edgeColor, arrowType, etc.) are filled from package defaults when omitted; analytical attributes such as weight are stored as-is.

  • Vertex sequence: an even number of vertices, taken pairwise (1st–2nd, 3rd–4th, ...) as the from/to endpoints of each edge.

...

Additional arguments (currently unused; reserved for future use).

Details

Adding edges does not invalidate the normalized layout. Node coordinates in @nodes are left untouched and normalizeGraphSpace does not need to be re-run.

For objects built with simplify = TRUE (the default), loop edges (from == to), parallel edges, and duplicate rows within value are dropped with a warning. Admissible edges in the same call are still added. To allow loops or parallel edges, rebuild the object with GraphSpace(g, simplify = FALSE).

Because adding an edge to a group of parallel edges changes the derived attributes curve_weight, is_multiple, and is_loop for all members of that group, the full edge table is recomputed from @graph after each assignment.

Value

A GraphSpace object with the new edges appended.

See Also

gs_add_nodes, gs_edge_attr, gs_subset_edges, gs_edges

Examples

library(RGraphSpace)
library(igraph)

g <- make_star(6, mode = "out")
gs <- GraphSpace(g, simplify = FALSE)
gs <- normalizeGraphSpace(gs)

# Functional form (pipe-friendly): returns a modified copy
gs <- gs_add_edges(gs, data.frame(from = "n2", to = "n3"))

# Assignment form: modifies gs in place
gs_add_edges(gs) <- data.frame(from = "n3", to = "n4")

# Add multiple edges with a numeric attribute
gs <- gs_add_edges(gs, data.frame(
  from   = c("n4", "n5"),
  to     = c("n5", "n6"),
  weight = c(0.8, 0.4)
))

# Add multiple edges as a vertex sequence
# (pairs: 1-2, 1-3, 1-4)
gs <- gs_add_edges(gs, c(1,2, 1,3, 1,4) )


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