diff --git a/R/nb2mat.R b/R/nb2mat.R index 58d5c4cd..64b46868 100644 --- a/R/nb2mat.R +++ b/R/nb2mat.R @@ -95,11 +95,20 @@ mat2listw <- function(x, row.names=NULL, style=NULL, zero.policy=NULL) { attr(neighbours, "call") <- NA attr(neighbours, "sym") <- is.symmetric.nb(neighbours, verbose=FALSE, force=TRUE) - if (any(card(neighbours) == 0L)) { + cnb <- card(neighbours) + if (any(cnb == 0L)) { if (!zero.policy) { warning("no-neighbour observations found, set zero.policy to TRUE;\nthis warning will soon become an error") } } + + NE <- length(neighbours) + sum(cnb) + if (get.SubgraphOption() && get.SubgraphCeiling() > NE) { + ncomp <- n.comp.nb(neighbours) + attr(neighbours, "ncomp") <- ncomp + if (ncomp$nc > 1) warning("neighbour object has ", ncomp$nc, " sub-graphs") + } + res <- list(style=style, neighbours=neighbours, weights=weights) class(res) <- c("listw", "nb") attr(res, "region.id") <- attr(neighbours, "region.id") diff --git a/man/card.Rd b/man/card.Rd index e547511e..b1c3a4dd 100644 --- a/man/card.Rd +++ b/man/card.Rd @@ -20,7 +20,7 @@ list. \details{\dQuote{nb} objects are stored as lists of integer vectors, where the vectors contain either the indices in the range \code{1:n} for \code{n} as \code{length(nb)} of the neighbours of region \code{i}, or \code{as.integer(0)} to signal no neighbours. The function \code{card(nb)} is used to extract the numbers of neighbours from the \dQuote{nb} object.} -\references{Bivand R, Pebesma EJ, Gomez-Rubio V, (2008) \emph{Applied Spatial Data Analysis with R}, Springer, New York, pp. 239-251; Bivand R, Portnov B, (2004) Exploring spatial data analysis techniques using R: the case of observations with no neighbours. In: Anselin L, Florax R, Rey S, (eds.), \emph{Advances in Spatial Econometrics, Methodology, Tools and Applications}. Berlin: Springer-Verlag, pp. 121-142.} +\references{Bivand R, Pebesma EJ, Gomez-Rubio V, (2008) \emph{Applied Spatial Data Analysis with R}, Springer, New York, pp. 239-251; Bivand R, Portnov B, (2004) Exploring spatial data analysis techniques using R: the case of observations with no neighbours. In: Anselin L, Florax R, Rey S, (eds.), \emph{Advances in Spatial Econometrics, Methodology, Tools and Applications}. Berlin: Springer-Verlag, pp. 121-142, \doi{10.1007/978-3-662-05617-2_6}.} \author{Roger Bivand \email{Roger.Bivand@nhh.no}}