diff --git a/R/listw2sn.R b/R/listw2sn.R index 890a6555..da86ec7b 100644 --- a/R/listw2sn.R +++ b/R/listw2sn.R @@ -21,7 +21,7 @@ listw2sn <- function(listw) { res } -sn2listw <- function(sn, style=NULL, zero.policy=NULL) { +sn2listw <- function(sn, style=NULL, zero.policy=NULL, from_mat2listw=FALSE) { if(!inherits(sn, "spatial.neighbour")) stop("not a spatial.neighbour object") if (is.null(zero.policy)) @@ -66,8 +66,12 @@ sn2listw <- function(sn, style=NULL, zero.policy=NULL) { res <- list(style=style, neighbours=nlist, weights=vlist) class(res) <- c("listw", "nb") if (any(card(res$neighbours) == 0L)) { - if (!zero.policy) { - stop("no-neighbour observations found, set zero.policy to TRUE") + if (!from_mat2listw) { + if (!zero.policy) { + stop("no-neighbour observations found, set zero.policy to TRUE") + } + } else { + warning("no-neighbour observations found, set zero.policy to TRUE;\nthis warning will soon become an error") } } if (!(is.null(attr(sn, "GeoDa")))) diff --git a/R/nb2mat.R b/R/nb2mat.R index d0ff9e9b..58d5c4cd 100644 --- a/R/nb2mat.R +++ b/R/nb2mat.R @@ -72,7 +72,8 @@ mat2listw <- function(x, row.names=NULL, style=NULL, zero.policy=NULL) { class(df) <- c(class(df), "spatial.neighbour") attr(df, "region.id") <- row.names attr(df, "n") <- dim(xC)[1] - res <- sn2listw(df, style=style, zero.policy=zero.policy) + res <- sn2listw(df, style=style, zero.policy=zero.policy, + from_mat2listw=TRUE) neighbours <- res$neighbours weights <- res$weights } else { @@ -96,7 +97,7 @@ mat2listw <- function(x, row.names=NULL, style=NULL, zero.policy=NULL) { verbose=FALSE, force=TRUE) if (any(card(neighbours) == 0L)) { if (!zero.policy) { - stop("no-neighbour observations found, set zero.policy to TRUE") + warning("no-neighbour observations found, set zero.policy to TRUE;\nthis warning will soon become an error") } } res <- list(style=style, neighbours=neighbours, weights=weights) diff --git a/man/listw2sn.Rd b/man/listw2sn.Rd index 6a6a9489..a237ca5c 100644 --- a/man/listw2sn.Rd +++ b/man/listw2sn.Rd @@ -10,13 +10,14 @@ The function makes a \code{"spatial neighbour"} object representation \code{"listw"} spatial weights object. \code{sn2listw()} is the inverse function to \code{listw2sn()}, creating a \code{"listw"} object from a \code{"spatial neighbour"} object. } \usage{ listw2sn(listw) -sn2listw(sn, style = NULL, zero.policy = NULL) +sn2listw(sn, style = NULL, zero.policy = NULL, from_mat2listw=FALSE) } \arguments{ \item{listw}{a \code{listw} object from for example \code{nb2listw}} \item{sn}{a \code{spatial.neighbour} object} \item{style}{default NULL, missing, set to "M" and warning given; if not "M", passed to \code{\link{nb2listw}} to re-build the object} \item{zero.policy}{default NULL, use global option value; if FALSE stop with error for any empty neighbour sets, if TRUE permit the weights list to be formed with zero-length weights vectors} + \item{from_mat2listw}{default FALSE, set TRUE if called from \code{mat2listw}} } \value{