1

I have already tried re-writing this code using dsn=path.expand and shapefile. However, this keeps giving me an error.

mapfile <-readOGR("/Users/kajoribanerjee/Documents/PhD/bayesian geoadditive model/india_2011.shp") 

Error in ogrListLayers(dsn = dsn) : Cannot open data source}

halfer
  • 19,824
  • 17
  • 99
  • 186
  • try `readOGR("/Users/kajoribanerjee/Documents/PhD/bayesian geoadditive model", "india_2011")` – loki Dec 08 '17 at 13:18

1 Answers1

0

In rgdal you have to name a layer destination (dsn) and a layer name (layer).
In case of a shapefile located at /home/user/folder/shapefile.shp that would be dsn = "/home/user/folder" and layer = "shapefile"

So you should use it like this:

mapfile <- readOGR("/Users/kajoribanerjee/Documents/PhD/bayesian geoadditive model", 
                   "india_2011")

You should also have a look at ?readOGR where it is stated that:

If reading a shapefile, the data source name (dsn= argument) is the folder (directory) where the shapefile is, and the layer is the name of the shapefile (without the .shp extension)

Another way is shown here by using raster::shapefile.

loki
  • 9,816
  • 7
  • 56
  • 82