Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Errors in the spdep::skater documentation #169

Closed
SpatLyu opened this issue Sep 28, 2024 · 2 comments
Closed

Errors in the spdep::skater documentation #169

SpatLyu opened this issue Sep 28, 2024 · 2 comments

Comments

@SpatLyu
Copy link

SpatLyu commented Sep 28, 2024

There are numerous errors in the demo of the spdep::skater documentation.

image

There were no issues when I tested it locally:

library(spdep)
#> Loading required package: spData
#> Loading required package: sf
#> Linking to GEOS 3.12.1, GDAL 3.8.4, PROJ 9.3.1; sf_use_s2() is TRUE
(GDAL37 <- as.numeric_version(unname(sf_extSoftVersion()["GDAL"])) >= "3.7.0")
#> [1] TRUE
file <- "etc/shapes/bhicv.gpkg.zip"
zipfile <- system.file(file, package="spdep")
if (GDAL37) {
  bh <- st_read(zipfile)
} else {
  td <- tempdir()
  bn <- sub(".zip", "", basename(file), fixed=TRUE)
  target <- unzip(zipfile, files=bn, exdir=td)
  bh <- st_read(target)
}
#> Reading layer `bhicv' from data source 
#>   `C:\Users\dell\R\pkgR\spdep\etc\shapes\bhicv.gpkg.zip' using driver `GPKG'
#> Simple feature collection with 98 features and 8 fields
#> Geometry type: POLYGON
#> Dimension:     XY
#> Bounding box:  xmin: -45.02175 ymin: -20.93007 xmax: -42.50321 ymax: -18.08342
#> Geodetic CRS:  Corrego Alegre 1970-72

dpad <- data.frame(scale(as.data.frame(bh)[,5:8]))

bh.nb <- poly2nb(bh)

lcosts <- nbcosts(bh.nb, dpad)

nb.w <- nb2listw(bh.nb, lcosts, style="B")

mst.bh <- mstree(nb.w,5)

par(mar=c(0,0,0,0))
plot(st_geometry(bh), border=gray(.5))
pts <- st_coordinates(st_centroid(bh))
#> Warning: st_centroid assumes attributes are constant over geometries
plot(mst.bh, pts, col=2, 
     cex.lab=.6, cex.circles=0.035, fg="blue", add=TRUE)

res1 <- skater(mst.bh[,1:2], dpad, 2)
table(res1$groups)
#> 
#>  1  2  3 
#> 18 23 57
opar <- par(mar=c(0,0,0,0))
plot(res1, pts, cex.circles=0.035, cex.lab=.7)

plot(res1, pts, cex.circles=0.035, cex.lab=.7,
     groups.colors=heat.colors(length(res1$ed)))

plot(st_geometry(bh), col=heat.colors(length(res1$edg))[res1$groups])

My local configuration is as follows:

sessionInfo()
#> R version 4.4.1 (2024-06-14 ucrt)
#> Platform: x86_64-w64-mingw32/x64
#> Running under: Windows 11 x64 (build 22631)
#> 
#> Matrix products: default
#> 
#> 
#> locale:
#> [1] LC_COLLATE=Chinese (Simplified)_China.utf8 
#> [2] LC_CTYPE=Chinese (Simplified)_China.utf8   
#> [3] LC_MONETARY=Chinese (Simplified)_China.utf8
#> [4] LC_NUMERIC=C                               
#> [5] LC_TIME=Chinese (Simplified)_China.utf8    
#> 
#> time zone: Asia/Shanghai
#> tzcode source: internal
#> 
#> attached base packages:
#> [1] stats     graphics  grDevices utils     datasets  methods   base     
#> 
#> loaded via a namespace (and not attached):
#>  [1] digest_0.6.37     fastmap_1.2.0     xfun_0.47         glue_1.7.0       
#>  [5] knitr_1.48        htmltools_0.5.8.1 rmarkdown_2.28    lifecycle_1.0.4  
#>  [9] cli_3.6.3         reprex_2.1.1      withr_3.0.1       compiler_4.4.1   
#> [13] rstudioapi_0.16.0 tools_4.4.1       evaluate_1.0.0    yaml_2.3.10      
#> [17] rlang_1.1.4       fs_1.6.4

Created on 2024-09-28 with reprex v2.1.1

@rsbivand rsbivand reopened this Sep 28, 2024
@rsbivand
Copy link
Member

rsbivand commented Sep 28, 2024

Struggling to get pkgdown to generate clean output, still working on this.

rsbivand added a commit that referenced this issue Sep 28, 2024
@rsbivand
Copy link
Member

rsbivand commented Sep 28, 2024

Seems OK now, thanks for reporting!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants