R/get_edge_info.R

Defines functions get_edge_info

Documented in get_edge_info

#' Get detailed information on edges
#'
#' @description
#'
#' Obtain a data frame with detailed information on edges and their
#' interrelationships within the graph.
#'
#' @inheritParams render_graph
#'
#' @return A data frame containing information specific to each edge within the
#'   graph.
#'
#' @examples
#' # Create a simple graph
#' graph <-
#'   create_graph() %>%
#'   add_gnm_graph(
#'     n = 5, m = 10,
#'     set_seed = 23)
#'
#' # Get information on the
#' # graph's edges
#' graph %>% get_edge_info()
#'
#' @export
get_edge_info <- function(graph) {

  # Validation: Graph object is valid
  check_graph_valid(graph)

  # For graphs with no edges, return NA
  if (nrow(graph$edges_df) == 0) {
    return(NA)
  }

  # Extract only the first 4 columns of the
  # edge data frame
  graph$edges_df %>%
    dplyr::select(id, from, to, rel)
}

Try the DiagrammeR package in your browser

Any scripts or data that you put into this service are public.

DiagrammeR documentation built on June 22, 2024, 11:21 a.m.