Skip to content

rows_update() is not sf friendly like other dplyr functions #5906

@andresrcs

Description

@andresrcs

When applied to an sf object, rows_update() throws the error message #> Error: Attempting to update missing rows. but if I transform the object to a tibble first, it works just fine, and then I can get back to an sf object with sf::st_as_sf(), which is not an ideal workflow. Could you make rows_update() function sf friendly like other dplyr functions?

library(dplyr)
library(rnaturalearth)

ne_states(country = "peru", returnclass = "sf") %>%
    select(name, name_len) %>% 
    filter(name %in% c("Arequipa", "Lima")) %>% 
    rows_update(tibble(name = "Arequipa", name_len = 0), by = "name")
#> Error: Attempting to update missing rows.

ne_states(country = "peru", returnclass = "sf") %>%
    select(name, name_len) %>% 
    filter(name %in% c("Arequipa", "Lima")) %>% 
    as_tibble() %>% 
    rows_update(tibble(name = "Arequipa", name_len = 0), by = "name")
#> # A tibble: 2 x 3
#>   name     name_len                                                     geometry
#>   <chr>       <int>                                           <MULTIPOLYGON [°]>
#> 1 Arequipa        0 (((-71.48848 -17.31799, -71.49771 -17.29713, -71.51452 -17.…
#> 2 Lima            4 (((-76.24919 -13.32044, -76.27428 -13.28729, -76.30695 -13.…

Created on 2021-06-04 by the reprex package (v2.0.0)

Metadata

Metadata

Assignees

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