if (requireNamespace("sf", quietly = TRUE)) {
library(sp)
auckland <- sf::st_read(system.file("shapes/auckland.shp", package="spData")[1])
auckland <- as(auckland, "Spatial")
plot(auckland)
if (requireNamespace("spdep", quietly = TRUE)) {
library(spdep)
auckland.nb <- poly2nb(auckland)
}
}
Run the code above in your browser using DataLab