From 935cdad84003d211c34ab1a6efeeeae6724a51f7 Mon Sep 17 00:00:00 2001 From: robinlovelace Date: Fri, 2 Aug 2024 14:17:57 +0100 Subject: [PATCH] Only run rnet_group() examples when igraph installed Close #565 --- R/rnet_group.R | 5 +++++ man/rnet_group.Rd | 6 ++++++ 2 files changed, 11 insertions(+) diff --git a/R/rnet_group.R b/R/rnet_group.R index 68e46052..d1fbf414 100644 --- a/R/rnet_group.R +++ b/R/rnet_group.R @@ -21,9 +21,13 @@ #' rnet_group representing the groups of each network element. In the latter #' case, the connectivity of the spatial object is derived from the sfNetwork #' object. +#' +#' @note These functions rely on the igraph package. If igraph is not installed, +#' the function will return a message. #' #' @family rnet #' @examples +#' if (requireNamespace("igraph", quietly = TRUE)) { #' rnet <- rnet_breakup_vertices(stplanr::osm_net_example) #' rnet$group <- rnet_group(rnet) #' plot(rnet["group"]) @@ -36,6 +40,7 @@ #' plot(rnet["group_louvain"]) #' rnet$group_fast_greedy <- rnet_group(rnet, igraph::cluster_fast_greedy) #' plot(rnet["group_fast_greedy"]) +#' } #' @export rnet_group <- function(rnet, ...) { UseMethod("rnet_group") diff --git a/man/rnet_group.Rd b/man/rnet_group.Rd index b0ccc051..edca5a24 100644 --- a/man/rnet_group.Rd +++ b/man/rnet_group.Rd @@ -65,7 +65,12 @@ functions are available: \verb{cluster_edge_betweenness, cluster_fast_greedy, cluster_label_prop,} \verb{cluster_leading_eigen, cluster_louvain, cluster_optimal, cluster_spinglass, cluster_walktrap} } +\note{ +These functions rely on the igraph package. If igraph is not installed, +the function will return a message. +} \examples{ +if (requireNamespace("igraph", quietly = TRUE)) { rnet <- rnet_breakup_vertices(stplanr::osm_net_example) rnet$group <- rnet_group(rnet) plot(rnet["group"]) @@ -79,6 +84,7 @@ plot(rnet["group_louvain"]) rnet$group_fast_greedy <- rnet_group(rnet, igraph::cluster_fast_greedy) plot(rnet["group_fast_greedy"]) } +} \seealso{ Other rnet: \code{\link{gsection}()},