Skip to content

rename_with() does not change the "sf_column" attribute. #2215

@UchidaMizuki

Description

@UchidaMizuki

Describe the bug
When a geometry column is renamed with rename_with(), the "sf_column" attribute is not changed.
This causes an error when printing the data.

To Reproduce

library(sf)
#> Warning: package 'sf' was built under R version 4.3.1
#> Linking to GEOS 3.11.2, GDAL 3.6.2, PROJ 9.2.0; sf_use_s2() is TRUE
library(tidyverse)

nc <- read_sf(system.file("shape/nc.shp", package = "sf"))
ret <- nc %>% 
  rename_with(str_to_title)
ret
#> Error in st_geometry.sf(x): attr(obj, "sf_column") does not point to a geometry column.
#> Did you rename it, without setting st_geometry(obj) <- "newname"?

Created on 2023-08-20 with reprex v2.0.2

``` r sessionInfo() #> R version 4.3.0 (2023-04-21 ucrt) #> Platform: x86_64-w64-mingw32/x64 (64-bit) #> Running under: Windows 11 x64 (build 22621) #> #> Matrix products: default #> #> #> locale: #> [1] LC_COLLATE=Japanese_Japan.utf8 LC_CTYPE=Japanese_Japan.utf8 #> [3] LC_MONETARY=Japanese_Japan.utf8 LC_NUMERIC=C #> [5] LC_TIME=Japanese_Japan.utf8 #> #> time zone: Asia/Tokyo #> tzcode source: internal #> #> attached base packages: #> [1] stats graphics grDevices utils datasets methods base #> #> loaded via a namespace (and not attached): #> [1] styler_1.10.1 digest_0.6.33 fastmap_1.1.1 xfun_0.39 #> [5] magrittr_2.0.3 glue_1.6.2 R.utils_2.12.2 knitr_1.43 #> [9] htmltools_0.5.5 rmarkdown_2.23 lifecycle_1.0.3 cli_3.6.1 #> [13] R.methodsS3_1.8.2 vctrs_0.6.3 reprex_2.0.2 withr_2.5.0 #> [17] compiler_4.3.0 R.oo_1.25.0 R.cache_0.16.0 purrr_1.0.1 #> [21] rstudioapi_0.15.0 tools_4.3.0 evaluate_0.21 yaml_2.3.7 #> [25] rlang_1.1.1 fs_1.6.2 sf::sf_extSoftVersion() #> GEOS GDAL proj.4 GDAL_with_GEOS USE_PROJ_H #> "3.11.2" "3.6.2" "9.2.0" "true" "true" #> PROJ #> "9.2.0" ```

Created on 2023-08-20 with reprex v2.0.2

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions