Skip to content

Instantly share code, notes, and snippets.

@arthurgailes
Created July 28, 2023 13:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save arthurgailes/0c10a78b3ec78f73104f2f66ac815221 to your computer and use it in GitHub Desktop.
Save arthurgailes/0c10a78b3ec78f73104f2f66ac815221 to your computer and use it in GitHub Desktop.
R: collapse and sf
# list and unlist an sf object
library(collapse)
library(sf)
library(testthat)
nc <- st_read(system.file("shape/nc.shp", package="sf"))
nc_list <- rsplit(nc, by = seq_len(nrow(nc)))
nc_collapse <- unlist2d(nc_list, idcols = FALSE, recursive = FALSE) |>
st_as_sf()
expect_equal(nc, nc_collapse)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment