r-lib / vctrs

Generic programming with typed R vectors
https://vctrs.r-lib.org
Other
289 stars 66 forks source link

`vctrs` doesn't like `geos_geometry` columns #1945

Open guslipkin opened 4 months ago

guslipkin commented 4 months ago

I was testing {geos} and came across the below error that said to report it. The issue is with the geometry column which is a geos_geometry polygon.

I know you usually wouldn't want to join this way on a geometry column.

.drawing_feature_to_geos <- function(feature) {
  feature |>
    unlist(recursive = FALSE) |>
    purrr::map(\(x) {
      x <-
        x |>
        unlist() |>
        `names<-`(c('x', 'y'))
      return(x)
    }) |>
    dplyr::bind_rows() |>
    (\(m) {
      geos::geos_make_polygon(m$x, m$y, crs = 4326)
    })() |>
    tibble::tibble() |>
    `colnames<-`('geometry')
}

geos1 <-
  list(list(
    list(-239.654911, -55.972427),
    list(-54.364094, -52.659505),
    list(-229.046736, -83.2853),
    list(-239.654911, -55.972427)
  )) |>
  .drawing_feature_to_geos() |>
  dplyr::mutate('id' = 1)

 geos1 |>
   dplyr::anti_join(
     y = {
       list(list(
         list(239.654911, 55.972427),
         list(54.364094, 52.659505),
         list(229.046736, 83.2853),
         list(239.654911, 55.972427)
       )) |>
         .drawing_feature_to_geos()
     }
   ) |>
   dplyr::mutate('id' = 1)
#> Joining with `by = join_by(geometry)`
#> Error in `vctrs::vec_locate_matches()`:
#> ! Unsupported vctrs type `list`.
#> ℹ In file 'type-info.c' at line 189.
#> ℹ This is an internal error that was detected in the vctrs package.
#>   Please report it at <https://github.com/r-lib/vctrs/issues> with a reprex (<https://tidyverse.org/help/>) and the full backtrace.

Created on 2024-07-02 with reprex v2.1.0