library(downloader)
library(sf)
library(data.table)
library(withr)
library(usmap)
library(RcensusPkg)
# Find the subsections for a county in Ohio
# Define a temporary, self deleting output folder for the downloaded shapefiles
output_dir <- withr::local_tempdir()
if(!dir.exists(output_dir)){
dir.create(output_dir)
}
# Define the fips values for state and county
ohio_hc_fips <- usmap::fips(state = "ohio", county = "holmes")
ohio_fips <- substr(ohio_hc_fips,1,2)
hc_fips <- substr(ohio_hc_fips,3,5)
# Define a filtering expression for the county
express <- parse(text = paste0("COUNTYFP == ", '"', hc_fips, '"'))
# Get the subsection sf object for the Ohio county
hc_ctysub_sf <- RcensusPkg::tiger_county_subsection_sf(
state = ohio_fips,
vintage = 2020,
general = TRUE,
express = express,
output_dir = output_dir,
delete_files = FALSE
)
Run the code above in your browser using DataLab