alarm-redist / redist

Simulation methods for legislative redistricting.
https://alarm-redist.github.io/redist/
GNU General Public License v2.0
66 stars 23 forks source link

Revdep check failures #175

Closed rsbivand closed 7 months ago

rsbivand commented 9 months ago

With forthcoming GDAL 3.8.1 and PROJ 9.3.1, and sf HEAD, multiple failures in use of st_agr: 00check.log.

After some debugging I see:

exiting from: redist.plot.adj(shp = x, adj = get_adj(x), ...)
exiting from: plot.redist_map(d)
Error in st_agr.default(x) : all(is.na(x)) is not TRUE

but I cannot debug this for you. I do not think that this is GDAL/PROJ related, it may be related to forthcoming sf, but your code is using magrittr pipes in functions, using tibbles, rlang, etc., so the possible sources of errors are not strictly limited (could be newer versions of any tidyverse packages). All the "agr" attributes are NA:

> attributes(d)
$names
 [1] "geoid10"  "pop"      "vap"      "obama"    "mccain"   "TotPop"  
 [7] "BlackPop" "HispPop"  "VAP"      "BlackVAP" "HispVAP"  "geometry"
[13] "adj"     

$row.names
 [1]  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25

$sf_column
[1] "geometry"

$agr
 geoid10      pop      vap    obama   mccain   TotPop BlackPop  HispPop 
    <NA>     <NA>     <NA>     <NA>     <NA>     <NA>     <NA>     <NA> 
     VAP BlackVAP  HispVAP      adj 
    <NA>     <NA>     <NA>     <NA> 
Levels: constant aggregate identity

$.sf_namespace
function () 
NULL
<bytecode: 0x55ce858>
<environment: namespace:sf>

$class
[1] "redist_map" "sf"         "tbl_df"     "tbl"        "data.frame"

$ndists
[1] 3

$pop_bounds
[1] 55430.28 58347.67 61265.05

$pop_col
[1] "pop"

$adj_col
[1] "adj"
> sf::st_agr(d)
 geoid10      pop      vap    obama   mccain   TotPop BlackPop  HispPop 
    <NA>     <NA>     <NA>     <NA>     <NA>     <NA>     <NA>     <NA> 
     VAP BlackVAP  HispVAP      adj 
    <NA>     <NA>     <NA>     <NA> 
Levels: constant aggregate identity

The traceback is:

> plot(d)
Error in st_agr.default(x) : all(is.na(x)) is not TRUE
> traceback()
17: stop(simpleError(msg, call = if (p <- sys.parent(1L)) sys.call(p)))
16: stopifnot(all(is.na(x)))
15: st_agr.default(x)
14: st_agr(x)
13: st_set_agr(NextMethod())
12: `[<-.sf`(`*tmp*`, idx, value = list(geometry = structure(list(
        structure(c(-9094457.8791782, -9109278.5759428, 3065428.18086654, 
        3075447.54300637), dim = c(2L, 2L), class = c("XY", "LINESTRING", 
        "sfg")), structure(c(-9094457.8791782, -9107696.123339, 3065428.18086654, 
        3064833.28216191), dim = c(2L, 2L), class = c("XY", "LINESTRING", 
        "sfg")), structure(c(-9094457.8791782, -9107279.03131695, 
        3065428.18086654, 3069141.85103023), dim = c(2L, 2L), class = c("XY", 
...
), class = c("sfc_LINESTRING", 
    "sfc"), precision = 0, bbox = structure(c(xmin = -9113752.65476168, 
    ymin = 3053200.30434356, xmax = -9064044.94017155, ymax = 3082690.06728483
    ), class = "bbox"))))
11: `[<-`(`*tmp*`, idx, value = list(geometry = structure(list(structure(c(-9094457.8791782, 
    -9109278.5759428, 3065428.18086654, 3075447.54300637), dim = c(2L, 
    2L), class = c("XY", "LINESTRING", "sfg")), structure(c(-9094457.8791782, 
...
), class = c("sfc_LINESTRING", 
    "sfc"), precision = 0, bbox = structure(c(xmin = -9113752.65476168, 
    ymin = 3053200.30434356, xmax = -9064044.94017155, ymax = 3082690.06728483
    ), class = "bbox"))))
10: FUN(X[[i]], ...)
9: lapply(data, function(layer_data) {
       if (!is_sf(layer_data)) {
           return(layer_data)
       }
       idx <- vapply(layer_data, inherits, what = "sfc", FUN.VALUE = logical(1L))
       layer_data[idx] <- lapply(layer_data[idx], sf::st_transform, 
           crs = params$crs)
       layer_data
   })
8: setup_data(...)
7: self$coord$setup_data(data, self$coord_params)
6: setup(..., self = self)
5: layout$setup(data, plot$data, plot$plot_env)
4: ggplot_build.ggplot(x)
3: ggplot_build(x)
2: print.ggplot(x)
1: (function (x, ...) 
   UseMethod("print"))(x)
> sessionInfo()
R version 4.3.2 (2023-10-31)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Fedora Linux 39 (Workstation Edition)

Matrix products: default
BLAS:   /home/rsb/topics/R/R432-share/lib64/R/lib/libRblas.so 
LAPACK: /home/rsb/topics/R/R432-share/lib64/R/lib/libRlapack.so;  LAPACK version 3.11.0

locale:
 [1] LC_CTYPE=en_GB.UTF-8       LC_NUMERIC=C              
 [3] LC_TIME=en_GB.UTF-8        LC_COLLATE=en_GB.UTF-8    
 [5] LC_MONETARY=en_GB.UTF-8    LC_MESSAGES=en_GB.UTF-8   
 [7] LC_PAPER=en_GB.UTF-8       LC_NAME=C                 
 [9] LC_ADDRESS=C               LC_TELEPHONE=C            
[11] LC_MEASUREMENT=en_GB.UTF-8 LC_IDENTIFICATION=C       

time zone: Europe/Oslo
tzcode source: system (glibc)

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] redist_4.1.1        redistmetrics_1.0.2

loaded via a namespace (and not attached):
 [1] gtable_0.3.4       dplyr_1.1.4        compiler_4.3.2     tidyselect_1.2.0  
 [5] Rcpp_1.0.11        stringr_1.5.1      parallel_4.3.2     doRNG_1.8.6       
 [9] scales_1.2.1       ggplot2_3.4.4      R6_2.5.1           generics_0.1.3    
[13] patchwork_1.1.3    classInt_0.4-10    sf_1.0-15          iterators_1.0.14  
[17] tibble_3.2.1       units_0.8-4        munsell_0.5.0      DBI_1.1.3         
[21] pillar_1.9.0       rlang_1.1.2        utf8_1.2.4         stringi_1.8.2     
[25] sys_3.4.2          cli_3.6.1          withr_2.5.2        magrittr_2.0.3    
[29] class_7.3-22       digest_0.6.33      foreach_1.5.2      grid_4.3.2        
[33] lifecycle_1.0.4    vctrs_0.6.4        KernSmooth_2.23-22 proxy_0.4-27      
[37] glue_1.6.2         codetools_0.2-19   rngtools_1.5.2     fansi_1.0.5       
[41] e1071_1.7-13       colorspace_2.1-0   tools_4.3.2        pkgconfig_2.0.3   
> sf::sf_extSoftVersion()
          GEOS           GDAL         proj.4 GDAL_with_GEOS     USE_PROJ_H 
      "3.12.1"        "3.8.1"        "9.3.1"         "true"         "true" 
          PROJ 
       "9.3.1" 
edzer commented 9 months ago

Thanks; should be fixed by https://github.com/r-spatial/sf/commit/6e7e5710ef3fa64b8f64681f116b59d20fc82119

christopherkenny commented 8 months ago

Testing from the current https://github.com/r-spatial/sf/commit/68257fa9af4102a2886c4900e716a391237f657a, I don't see any issue, so I think it is fixed by your above commit. Thanks @edzer and @rsbivand.