Reputation: 1
I am trying to read in a .shp file with readOGR() but I keep getting one of two errors
When I use this code:
county.map <- readOGR(paste0("C:/Users/name/Documents/HospMarket/geog/cb_2017_us_county_5m.shp"),layer = "cb_2017_us_county_5m",verbose = FALSE)
I get this error:
Error in ogrInfo(dsn = dsn, layer = layer, encoding = encoding, use_iconv = use_iconv, : Cannot open data source
One fix I read about led me to write this instead:
county.map <- readOGR(paste0("C:/Users/name/Documents/HospMarket/geog"),layer = "cb_2017_us_county_5m",verbose = FALSE)
Here I get this error code:
Error in ogrInfo(dsn = dsn, layer = layer, encoding = encoding, use_iconv = use_iconv, : Cannot open layer
I am really at a loss of what else to do, I am 99.99% sure that everything is spelled correctly, what else could this mean? I am relatively new to R so I am still learning. Thanks!
Upvotes: 0
Views: 773
Reputation: 8136
You can use the following code
library(rgdal)
county.map <- readOGR(dsn = "C:/Users/name/Documents/HospMarket/geog", #Provide the directory of shp file
layer = "cb_2017_us_county_5m", #Provide the name of the shp file without extension (.shp)
verbose = FALSE)
Upvotes: 0