-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Revert "update igraph use; interrupt depht-first search in n.comp.nb,…
… add igraph argument to n.comp.nb" This reverts commit e64720c.
- Loading branch information
Showing
11 changed files
with
34 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,13 @@ | ||
# Copyright 2001 by Nicholas Lewin-Koh, igraph added RSB 2024 | ||
# Copyright 2001 by Nicholas Lewin-Koh | ||
# | ||
|
||
|
||
n.comp.nb <- function(nb.obj, igraph=FALSE){ | ||
n.comp.nb <- function(nb.obj){ | ||
if(!inherits(nb.obj,"nb"))stop("not a neighbours list") | ||
stopifnot(is.logical(igraph)) | ||
stopifnot(length(igraph) == 1L) | ||
nb.sym <- is.symmetric.nb(nb.obj) | ||
if (igraph) { | ||
if (!requireNamespace("igraph", quietly=TRUE)) { | ||
igraph <- !igraph | ||
warning("igraph not available, set FALSE") | ||
} | ||
} | ||
if (!igraph) { | ||
if (!nb.sym) nb.obj <- make.sym.nb(nb.obj) | ||
comp <- rep(0,length(nb.obj)) | ||
comp <- .Call("g_components", nb.obj, as.integer(comp), PACKAGE="spdep") | ||
answ <- list(nc=length(unique(comp)), comp.id=comp) | ||
} else { | ||
stopifnot(requireNamespace("igraph", quietly=TRUE)) | ||
stopifnot(requireNamespace("spatialreg", quietly=TRUE)) | ||
B <- as(nb2listw(nb.obj, style="B", zero.policy=TRUE), "CsparseMatrix") | ||
|
||
g1 <- igraph::graph_from_adjacency_matrix(B, | ||
mode=ifelse(nb.sym, "undirected", "directed")) | ||
c1 <- igraph::components(g1, mode="weak") | ||
answ <- list(nc=c1$no, comp.id=c1$membership) | ||
} | ||
nb.obj <- make.sym.nb(nb.obj) | ||
comp <- rep(0,length(nb.obj)) | ||
comp <- .Call("g_components", nb.obj, as.integer(comp), PACKAGE="spdep") | ||
answ <- list(nc=length(unique(comp)), comp.id=comp) | ||
answ | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters