R/get_graph_name.R

Defines functions get_graph_name

Documented in get_graph_name

#' Get graph name
#'
#' @description
#'
#' Get the name of a graph object of class `dgr_graph`.
#'
#' @inheritParams render_graph
#'
#' @return A single-length character vector with the assigned graph name. If a
#'   graph name has not been set, NA is returned.
#'
#' @examples
#' # Create an empty graph
#' graph <- create_graph()
#'
#' # Provide the new graph with a name
#' graph <-
#'   set_graph_name(
#'     graph,
#'     name = "the_name")
#'
#' # Get the graph's name
#' graph %>% get_graph_name()
#'
#' @export
get_graph_name <- function(graph) {

  # Get the name of the function
  fcn_name <- get_calling_fcn()

  # Validation: Graph object is valid
  if (graph_object_valid(graph) == FALSE) {

    emit_error(
      fcn_name = fcn_name,
      reasons = "The graph object is not valid")
  }

  graph$graph_info$graph_name
}

Try the DiagrammeR package in your browser

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

DiagrammeR documentation built on May 31, 2023, 6:14 p.m.