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