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

distinct() on an empty sf tibble drops geometry column and sf properties #2204

Closed
avsdev-cw opened this issue Jul 21, 2023 · 1 comment
Closed

Comments

@avsdev-cw
Copy link

When using distinct on an empty sf tibble (in a long chain, for example), the geometry column is dropped along with all the sf properties

tib <- tibble::tibble(
    var_x = integer(0),
    var_y = character(0),
    geometry = sf::st_sfc(crs =4326)
)
tib.sf <- sf::st_sf(tib)
print(tib.sf)
#> Simple feature collection with 0 features and 2 fields
#> Bounding box:  xmin: NA ymin: NA xmax: NA ymax: NA
#> Geodetic CRS:  WGS 84
#> # A tibble: 0 × 3
#> # ℹ 3 variables: var_x <int>, var_y <chr>, geometry <GEOMETRY [°]>
dplyr::distinct(tib.sf)
#> # A tibble: 0 × 2
#> # ℹ 2 variables: var_x <int>, var_y <chr>
```R sessionInfo() #> R version 4.0.4 (2021-02-15) #> Platform: x86_64-pc-linux-gnu (64-bit) #> Running under: BunsenLabs GNU/Linux 10.5 (Lithium) #> #> Matrix products: default #> BLAS: /usr/lib/x86_64-linux-gnu/openblas-pthread/libblas.so.3 #> LAPACK: /usr/lib/x86_64-linux-gnu/openblas-pthread/libopenblasp-r0.3.13.so #> #> 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 #> #> attached base packages: #> [1] stats graphics grDevices utils datasets methods base #> #> loaded via a namespace (and not attached): #> [1] Rcpp_1.0.10 pillar_1.9.0 compiler_4.0.4 highr_0.8 #> [5] R.methodsS3_1.8.1 R.utils_2.11.0 class_7.3-18 tools_4.0.4 #> [9] digest_0.6.27 evaluate_0.14 lifecycle_1.0.3 tibble_3.2.1 #> [13] R.cache_0.15.0 pkgconfig_2.0.3 rlang_1.1.0 reprex_2.0.0 #> [17] cli_3.4.1 DBI_1.1.3 yaml_2.2.1 xfun_0.28 #> [21] fastmap_1.1.0 e1071_1.7-4 s2_1.1.4 dplyr_1.1.1 #> [25] withr_2.5.0 styler_1.6.2 stringr_1.5.0 knitr_1.31 #> [29] generics_0.1.0 fs_1.5.0 vctrs_0.6.1 tidyselect_1.2.0 #> [33] classInt_0.4-3 grid_4.0.4 glue_1.6.2 R6_2.5.0 #> [37] sf_1.0-14 fansi_0.4.2 rmarkdown_2.11 purrr_1.0.1 #> [41] magrittr_2.0.1 units_0.8-2 backports_1.2.1 htmltools_0.5.4 #> [45] utf8_1.2.1 KernSmooth_2.23-18 stringi_1.5.3 wk_0.7.3 #> [49] R.oo_1.24.0 ```
@avsdev-cw avsdev-cw changed the title distinct on an empty sf tibble drops geometry column and sf properties distinct() on an empty sf tibble drops geometry column and sf properties Jul 21, 2023
@edzer edzer closed this as completed in 9a7f212 Aug 6, 2023
@edzer
Copy link
Member

edzer commented Aug 6, 2023

Thanks, should work now.

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