Error opening SHP file in R using maptools readShapePoly

Steve Senior picture Steve Senior · May 17, 2013 · Viewed 34k times · Source

I am new to R and was following the following tutorial on the ggplot2 package found here. However the readShapePoly() function throws an error whenever I try to load the basic shapefile. I have used the following code:

library("ggplot2")
library("gpclib")
library("maptools")
setwd("~/Documents/R Projects/Intro to ggplot2") 
#Intro to ggplot 2 contains the .shp file and associated data
sport <- readShapePoly("london_sport.shp")

which gets me:

Error in getinfo.shape(filen) : Error opening SHP file

I have tried omitting the file extension. I have also tried downloading other .shp files which throw the same error too. I have also tried calling readShapePoly using the full file path, which doesn't work either. I am using R studio (mac OSX), but I get the same error using the standard R window. I have tried the suggestions on the previous closed threat "Error opening SHP file in Rstudio", but to no avail.

Edit: the error was with a missing .dbf file. Thanks to @Spacedman for the fix.

Answer

Aaron Lelevier picture Aaron Lelevier · Mar 24, 2014

I had a similar issue, and it was because there were several other files along with the '*.shp' shape file in the zip package that I downloaded. Then I only moved the shape file to another folder and it didn't work. When including all files together, it was fine and I could readShapeSpatial() function okay.