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

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

Closed
andresrcs opened this issue Jun 4, 2021 · 3 comments
Closed

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

andresrcs opened this issue Jun 4, 2021 · 3 comments
Assignees

Comments

@andresrcs
Copy link

andresrcs commented Jun 4, 2021

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)

@romainfrancois
Copy link
Member

Can you have a look @krlmlr ?

@krlmlr
Copy link
Member

krlmlr commented Jun 13, 2021

Thanks. My first instinct is to suggest implementing rows_update() and friends in the sf package, even if it's with a wrapper as_tibble() %>% rows_update() %>% st_as_sf() . I'll take a look and propose something.

@hadley hadley closed this as completed Sep 16, 2021
@jbeaulie
Copy link

This issue was 'closed as completed' but the problem documented in the original post persists with dplyr_1.1.4, except the error message has changed:
Error in rows_update():
! Can't reconstruct data frame.
✖ The [ method for class <sf/data.frame> must return a data frame with 1 column.
ℹ It returned a <sf/data.frame> of 2 columns.

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

5 participants