R/remove_subnetworks.R

Defines functions remove_subnetworks

Documented in remove_subnetworks

#' Find and return the largest subnetwork
#'
#' @param input Graph object
#'
#' @return Largest subnetwork from the input network list as an igraph object
#'
#' @importFrom igraph components induced_subgraph
#'
#' @references None.
#'
#' @seealso <https://www.github.com/travis-m-blimkie/networker>
#'
remove_subnetworks <- function(input) {
  igraph::V(input)$comp <- components(input)$membership

  max_subnet_id <- igraph::V(input)$comp %>%
    table() %>%
    tibble::enframe() %>%
    arrange(desc(value)) %>%
    magrittr::extract2(1, 1) %>%
    as.numeric()

  induced_subgraph(input, igraph::V(input)$comp == max_subnet_id)
}
travis-m-blimkie/networker documentation built on June 3, 2023, 10:17 p.m.