Search code examples
rshapefile

Cannot open shp file


I'm trying to read a shp file but to no success. I already tried all the answers in this readOGR() cannot open file and none of them worked for me.

Using

file.exists('../Downloads/NUTS_RG_03M_2013_4326_LEVL_2.shp')

I get back TRUE

But when I run

shapefile('../Downloads/NUTS_RG_03M_2013_4326_LEVL_2.shp')

I get

Error: file.exists(extension(x, ".shp")) is not TRUE

I tried running

readOGR(dsn = "..Downloads/NUTS_RG_03M_2013_4326_LEVL_2.shp", layer ="NUTS_RG_03M_2013_4326_LEVL_2")

and get the error

Error in ogrInfo(dsn = dsn, layer = layer, encoding = encoding, use_iconv = use_iconv,  : 
  Cannot open data source

Also tried

readOGR(dsn=path.expand("../Downloads"), layer="NUTS_RG_03M_2013_4326_LEVL_2")

and got

Error in ogrInfo(dsn = dsn, layer = layer, encoding = encoding, use_iconv = use_iconv,  : 
  Cannot open layer

I don´t know what else to try


Solution

  • I was facing the same issue, but got around it when I put other files that were in the same .zip file as my .shp file together with it in the working directory. Files with extensions such as .shx, .qpg, .prj and .cpj. I didn't change anything in the code. Just added the files.