tidyr's unnest will soon allow for unnesting some list columns, but not others (https://github.com/tidyverse/tidyr/issues/328). That means you can unnest sf objects, as long as you tell unnest that the geometry column is a list column that should be preserved.
I can write a PR for this if you're okay adding another tidyverse method to sf.
Demo:
library(sf)
library(dplyr)
library(tidyr)
nc <- st_read(system.file("shape/nc.shp", package = "sf")) %>%
slice(1:3) %>%
select(NAME) %>%
mutate(y = strsplit(c("a", "d,e,f", "g,h"), ","))
# This will work soon, with no changes to sf:
unnest(nc, .preserve = geometry)
# The .preserve = geometry could be made automatic by adding an
# unnest method that knows to preserve the geometry column(s)
unnest(nc)
tidyr's
unnest
will soon allow for unnesting some list columns, but not others (https://github.com/tidyverse/tidyr/issues/328). That means you canunnest
sf objects, as long as you tellunnest
that the geometry column is a list column that should be preserved.I can write a PR for this if you're okay adding another tidyverse method to sf.
Demo: