Skip to content

Commit

Permalink
Update graph-functions-misc.R
Browse files Browse the repository at this point in the history
adding functions
  • Loading branch information
leoniedu authored Feb 11, 2025
1 parent ecd309f commit 5787bd5
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions R/graph-functions-misc.R
Original file line number Diff line number Diff line change
Expand Up @@ -288,3 +288,42 @@ remap_verts_with_turn_penalty <- function (graph, pts, from = TRUE) {

return (pts)
}

#' Get single graph column containing the edge ID
#' @noRd
find_edge_id_col <- function (graph) {
# First try exact matches
edge_id_col <- grep ("^edge_id$", names (graph), ignore.case = TRUE)

# If no exact match, try broader patterns
if (length (edge_id_col) != 1) {
# Look for columns ending in edge_id or edge
edge_id_col <- grep ("edge_id$|edge$", names (graph), ignore.case = TRUE)

if (length (edge_id_col) > 1) {
stop ("Unable to determine unique column for edge IDs")
} else if (length (edge_id_col) == 0) {
edge_id_col <- NA_integer_
}
}
return (edge_id_col)
}

#' Get single graph column containing component IDs
#' @noRd
find_component_col <- function (graph) {
# First try exact match
comp_col <- grep ("^component$", names (graph), ignore.case = TRUE)

# If no exact match, try broader pattern
if (length (comp_col) != 1) {
comp_col <- grep ("comp", names (graph), ignore.case = TRUE)

if (length (comp_col) > 1) {
stop ("Unable to determine unique column for components")
} else if (length (comp_col) == 0) {
comp_col <- NA_integer_
}
}
return (comp_col)
}

0 comments on commit 5787bd5

Please sign in to comment.