create_nodes: Create Canonical Node and Edge Tables

View source: R/ingest.R

create_nodesR Documentation

Create Canonical Node and Edge Tables

Description

Build canonical node and edge tables from ordinary metadata frames.

Usage

create_nodes(
  data,
  type,
  id_col,
  label_col = NULL,
  attr_cols = NULL,
  prefix = TRUE,
  dedupe = TRUE
)

create_edges(
  data,
  from_col,
  to_col,
  from_type,
  to_type,
  relation,
  attr_cols = NULL,
  allow_missing = FALSE,
  dedupe = TRUE,
  from_prefix = TRUE,
  to_prefix = TRUE
)

Arguments

data

A data.frame containing entity or relationship columns.

type, from_type, to_type

Supported node types such as "Sample" or "Subject".

id_col

Column containing the source identifier for the node type.

label_col

Optional column used for node labels.

attr_cols

Optional columns stored in the attrs list-column.

prefix

If TRUE, prepend typed prefixes such as sample: to node identifiers.

dedupe

If TRUE, collapse duplicate identifiers or duplicate edges only when the retained definition is identical.

from_col, to_col

Source and target identifier columns for edge creation.

relation

Canonical edge type.

allow_missing

If TRUE, drop rows with missing edge endpoints instead of erroring.

from_prefix, to_prefix

Whether to prepend typed prefixes when constructing the edge endpoint identifiers. Defaults preserve the canonical prefixed-ID format.

Details

The package uses typed node identifiers such as sample:S1 as the canonical graph representation. If you create node sets with prefix = FALSE, the corresponding edge endpoints must use matching prefix settings via from_prefix and to_prefix.

When dedupe = TRUE, exact duplicate node or edge definitions are collapsed, but conflicting definitions for the same canonical node identifier or edge relation are rejected with an error.

Value

For create_nodes(), a graph_node_set. For create_edges(), a graph_edge_set.

Examples

meta <- data.frame(
  sample_id = c("S1", "S2"),
  subject_id = c("P1", "P2")
)

samples <- create_nodes(meta, type = "Sample", id_col = "sample_id")
edges <- create_edges(
  meta,
  from_col = "sample_id",
  to_col = "subject_id",
  from_type = "Sample",
  to_type = "Subject",
  relation = "sample_belongs_to_subject"
)

splitGraph documentation built on July 3, 2026, 5:06 p.m.