[R-sig-Geo] looping sp data

ahelmore aelmore at usgs.gov
Fri Jul 22 16:45:57 CEST 2011


Hi there,

I have a rather lengthy bit of code I want to run on a series of point
files, but I can't even figure out how to load shapefiles in a simple loop. 
Since readOGR takes shapefile names without the .shp extension, I thought I
could make a list of unduplicated file names, sans extensions and use that
to run the loop, but I'm getting a missing layer error.  After staring at it
for way too long, I'm looking for a leg up.  Can anyone tell me where my
thinking/code is off?

Here's what isn't working:

patt.xml <- ".*eden.*xml.*"
patt.shp <- ".*eden.*shp.*"
data.shp.xml <-list.files(pattern=patt.shp) # list of eden .shp & .shp.xml
data
data.xml <-list.files(pattern=patt.xml) # list of eden .shp.xml data
data.shp <- data.shp.xml[!data.shp.xml %in% data.xml] # list of .shp files
data.eden <- gsub(".shp","",data.shp) #stripping the extension


for (x in 1:length(data.eden)) {
     data<-readOGR(x) 
     summary(data)   
}

It gives me:  Error in readOGR(x) : missing layer

--
View this message in context: http://r-sig-geo.2731867.n2.nabble.com/looping-sp-data-tp6610701p6610701.html
Sent from the R-sig-geo mailing list archive at Nabble.com.



More information about the R-sig-Geo mailing list