Skip to content

Instantly share code, notes, and snippets.

@dankkom
Created April 4, 2024 16:48
Show Gist options
  • Save dankkom/ff4c531d39d35cd029679625abb451f2 to your computer and use it in GitHub Desktop.
Save dankkom/ff4c531d39d35cd029679625abb451f2 to your computer and use it in GitHub Desktop.
read_shp(): R function to read zipped shapefiles
read_shp <- function(filepath) {
# If zipped
if (stringr::str_ends(filepath, ".zip")) {
temp1 <- tempfile()
unzip(zipfile = filepath, exdir = temp1)
d <- sf::read_sf(temp1)
unlink(temp1, recursive = TRUE)
return(d)
}
# If not zipped
sf::read_sf(filepath)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment