I need to work with several shapefiles in a project in R.
Therefore i would like to iterate the readOGR function to load these files in a list. Later I can use plyr or construct a loop to do the same operation on every shapefile in the list.
here is a minimum reproducible example:
library("rgdal")
setwd("your.path.here")
download.file("http://www.naturalearthdata.com/http//www.naturalearthdata.com/download/10m/cultural/ne_10m_admin_0_countries.zip","ne_10m_admin_0_countries.zip")
unzip("ne_10m_admin_0_countries.zip")
# works like this:
my.shapefile<-readOGR("your.path.here","ne_10m_admin_0_countries")
plot(my.shapefile)
# does not work like this
shapefile.list<-list(length=20)
shapefile.list[1]<-readOGR("your.path.here","ne_10m_admin_0_countries")
plot(shapefile.list[1])
Error message is
Error in xy.coords(x, y, xlabel, ylabel, log) : 'x' is a list, but does not have components 'x' and 'y'