Skip to content

Commit

Permalink
Fix #113
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasp85 committed Nov 7, 2023
1 parent b48aa08 commit 3411b5e
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 0 deletions.
2 changes: 2 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ export(dfs_rank_out)
export(distinct)
export(drop_na)
export(edge_is_between)
export(edge_is_bridge)
export(edge_is_from)
export(edge_is_incident)
export(edge_is_loop)
Expand Down Expand Up @@ -449,6 +450,7 @@ importFrom(igraph,betweenness)
importFrom(igraph,bfs)
importFrom(igraph,bibcoupling)
importFrom(igraph,biconnected_components)
importFrom(igraph,bridges)
importFrom(igraph,clique_num)
importFrom(igraph,closeness)
importFrom(igraph,cluster_edge_betweenness)
Expand Down
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
(#152)
* Added the whole family of `slice_*()` functions from dplyr (#128)
* Added methods for `tidyr::replace_na()` and `tidyr::drop_na()` (#114)
* Added `edge_is_bridge()` for querying whether an edge is a bridge edge (#113)

# tidygraph 1.2.3

Expand Down
9 changes: 9 additions & 0 deletions R/edge.R
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,13 @@ edge_is_incident <- function(nodes) {
nodes <- as_ind(nodes, graph_order())
edges$from %in% nodes | edges$to %in% nodes
}
#' @describeIn edge_types Query whether an edge is a bridge (ie. it's removal
#' will increase the number of components in a graph)
#' @importFrom igraph bridges gsize
#' @export
edge_is_bridge <- function() {
expect_edges()
graph <- .G()
seq_len(gsize(graph)) %in% bridges(graph)
}

3 changes: 3 additions & 0 deletions tests/testthat/test-edge_types.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ test_that("edge types return logical", {
expect_type(get_type(gr, edge_is_loop()), 'logical')
expect_type(get_type(gr, edge_is_multiple()), 'logical')
expect_type(get_type(gr, edge_is_mutual()), 'logical')
expect_type(get_type(gr, edge_is_bridge()), 'logical')
})
test_that("edge types return correct length", {
gr <- create_notable('bull') %>%
Expand All @@ -22,6 +23,7 @@ test_that("edge types return correct length", {
expect_length(get_type(gr, edge_is_loop()), igraph::gsize(gr))
expect_length(get_type(gr, edge_is_multiple()), igraph::gsize(gr))
expect_length(get_type(gr, edge_is_mutual()), igraph::gsize(gr))
expect_length(get_type(gr, edge_is_bridge()), igraph::gsize(gr))
})
test_that("edge types require edge active", {
gr <- create_notable('bull') %>%
Expand All @@ -33,4 +35,5 @@ test_that("edge types require edge active", {
expect_error(get_type(gr, edge_is_loop()))
expect_error(get_type(gr, edge_is_multiple()))
expect_error(get_type(gr, edge_is_mutual()))
expect_error(get_type(gr, edge_is_bridge()))
})

0 comments on commit 3411b5e

Please sign in to comment.