Open elipousson opened 1 year ago
Hi @elipousson I have just seen this. I already raised a similar issue (though relating to list_rbind()) on the purrr repo. (Though a few days after you raised this issue!) https://github.com/tidyverse/purrr/issues/1076
It wouldn't be a big issue but purrr::list_rbind()
is being recommended as the replacement for the deprecated purrr::map_dfr()
(and the row-binding functions have the same issue as the column-binding function) so I expect there may be some confused users. It is relatively straightforward to fix in a script but I'm not sure how it could be handled by sf or if vctrs or purrr would allow this edge case.
Here is an example showind the issue with purrr::list_rbind()
(and the simple fix):
nc <- sf::read_sf(system.file("shape/nc.shp", package = "sf"))
nc_bind_rows <- dplyr::bind_rows(
nc[2, ],
nc[1, ]
)
class(nc_bind_rows)
#> [1] "sf" "tbl_df" "tbl" "data.frame"
nc_vec_rbind <- vctrs::vec_rbind(
nc[2, ],
nc[1, ]
)
class(nc_vec_rbind)
#> [1] "data.frame"
class(sf::st_as_sf(nc_vec_rbind))
#> [1] "sf" "data.frame"
Created on 2023-06-26 with reprex v2.0.2
I do think this is an issue with vctrs or purrr not with sf though.
To be clear, map_dfr()
is not deprecated; it's superseded.
Thanks for that reminder!
Combining a simple feature object with a data.frame using
purrr::list_cbind()
orvctrs::vec_cbind()
returns a data.frame instead of an sf object as expected.Created on 2023-04-29 with reprex v2.0.2
I'm pretty sure that both approaches worked with sf objects previously so I'm unsure if there was a change in vctrs or a change in sf.