vctrs icon indicating copy to clipboard operation
vctrs copied to clipboard

sf geometry column returned with "vctrs:::common_class_fallback" class

Open DavisVaughan opened this issue 3 years ago • 0 comments

Seen in https://github.com/tidyverse/dplyr/issues/5780, somehow this geometry column isn't being reworked back into an sf object, and instead the common-class-fallback wrapper is returned.

This seems to happen with >1 elements to vec_rbind() + setting the .names_to argument

library(sf)
library(vctrs)

a <- st_as_sf(data.frame(ID = 1, geometry = st_sfc(st_point(c(1, 1)))))
a
#> Simple feature collection with 1 feature and 1 field
#> geometry type:  POINT
#> dimension:      XY
#> bbox:           xmin: 1 ymin: 1 xmax: 1 ymax: 1
#> CRS:            NA
#>   ID    geometry
#> 1  1 POINT (1 1)

vec_rbind(a)$geometry
#> Geometry set for 1 feature 
#> geometry type:  POINT
#> dimension:      XY
#> bbox:           xmin: 1 ymin: 1 xmax: 1 ymax: 1
#> CRS:            NA
#> POINT (1 1)

vec_rbind(a, .names_to = "id")$geometry
#> Geometry set for 1 feature 
#> geometry type:  POINT
#> dimension:      XY
#> bbox:           xmin: 1 ymin: 1 xmax: 1 ymax: 1
#> CRS:            NA
#> POINT (1 1)

vec_rbind(a, a)$geometry
#> Geometry set for 2 features 
#> geometry type:  POINT
#> dimension:      XY
#> bbox:           xmin: 1 ymin: 1 xmax: 1 ymax: 1
#> CRS:            NA
#> POINT (1 1)
#> POINT (1 1)

vec_rbind(a, a, .names_to = "id")$geometry
#> [[1]]
#> POINT (1 1)
#> 
#> [[2]]
#> POINT (1 1)
#> 
#> attr(,"precision")
#> [1] 0
#> attr(,"bbox")
#> xmin ymin xmax ymax 
#>   NA   NA   NA   NA 
#> attr(,"crs")
#> Coordinate Reference System: NA
#> attr(,"classes")
#> character(0)
#> attr(,"n_empty")
#> [1] 0
#> attr(,"fallback_class")
#> [1] "sfc_GEOMETRY" "sfc"         
#> attr(,"class")
#> [1] "vctrs:::common_class_fallback"

Created on 2021-03-03 by the reprex package (v1.0.0)

DavisVaughan avatar Mar 04 '21 00:03 DavisVaughan