I don't understand why I should choose readOGR() over readShapePoly.

What are all the different ways of doing this, and why should I choose one over another?

| improve this question | | | | |
  • 3
    Could you edit your question and describe what you have tried so far, and what your needs for shapefiles are? – Simbamangu May 4 '19 at 16:06
  • If you read the help file for R is says readShapePoly is deprecated and don't use, use readOGR(), so I think your question is obsolete. – Hornbydd May 6 '19 at 21:36

This is explained in the documentation for maptools::readShapePoly, which you should read when asking questions of a function:


     The use of this function is deprecated and it is not being
     maintained. Use ‘rgdal::readOGR()’ or ‘sf::st_read()’ instead -
     both of these read the coordinate reference system from the input
     file, while this deprecated function does not.For writing, use
     ‘rgdal::writeOGR()’ or ‘sf::st_write()’ instead.

The difference between rgdal::readOGR and sf::st_read is that they create very different R objects to store the information in the shapefile, and functions from one package are incompatible with data from the other.

You may also find people using raster::shapefile to read shapefiles, this is a convenience wrapper so instead of doing readOGR("/data/maplibrary/world","countries") you do shapefile("/data/maplibrary/world/countries.shp") - ie you specify the path to the .shp file in one argument and not split into folder and shapefile name.

| improve this answer | | | | |

Not the answer you're looking for? Browse other questions tagged or ask your own question.