add_edges: Add Edges to a Network

View source: R/wrangle-edit.R

add_edgesR Documentation

Add Edges to a Network

Description

Appends edges between existing nodes. An endpoint that is not a node of the network raises a cograph_bad_selection error.

Usage

add_edges(x, from, to, weight = 1, ..., keep_format = FALSE, directed = NULL)

Arguments

x

Network input.

from

Source nodes, by label or index.

to

Target nodes, by label or index. The same length as from.

weight

Numeric weight for the new edges, length 1 or length(from). Default 1.

...

Named vectors of extra edge attributes, length 1 or length(from).

keep_format

Logical. Return the input format when TRUE.

directed

Logical or NULL. If NULL (default), auto-detect.

Value

A cograph_network with the new edges, or the input format when keep_format = TRUE. An edge that already exists has its weight replaced, and a cograph_edges_replaced warning says how many.

Note

When the igraph package is attached it masks this function with igraph::add_edges(), which takes an igraph object. Use cograph::add_edges() to be explicit.

See Also

remove_edges, add_nodes, bind_networks

Examples

add_edges(regulation_net, from = "Share", to = "Explore", weight = 0.5)

cograph documentation built on Nov. 19, 2026, 5:07 p.m.