[R] Importing multiple shapefiles to run a loop

From: Nathaniel <nathanielrayl_at_hotmail.com>
Date: Mon, 14 Mar 2011 12:09:55 -0700 (PDT)


Hi R Users,

I commonly import multiple .csv files and then write loops to work with those files like this:

>setwd('C://Nathaniel/R/allfiles')
>files<-list.files()
>allfiles<-lapply(t1,read.csv)
>for (i in 1:47) {
> t1<-allfiles[[i]]

etc. etc.

I have written a script that I would like to loop to work with a folder of 400+ .shp files. Is there an equivalent way to read in all the shapefiles so that I can run a loop?

I tried this:

>setwd('C://Nathaniel/R/shapefiles')
>t1<-list.files()
>t2<-lapply(t1,readShapePoly)

which returned this error:

"Error in Fun(c("shape1.dbf", "shape1.prj", "shape1.sbn", "shape1.sbx", :

   missing layer"

and I tried this:

>setwd('C://Nathaniel/R/shapefiles')
>t1<-list.files()
>t2<-lapply(t1,readOGR)

which returned this error:

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

I've searched the archives and wasn't able to find anything like this. My understanding of R code is rudimentary, so any help would be greatly appreciated. Thanks for considering my problem.

Best regards,

Nathaniel

--
View this message in context: http://r.789695.n4.nabble.com/Importing-multiple-shapefiles-to-run-a-loop-tp3354742p3354742.html
Sent from the R help mailing list archive at Nabble.com.

______________________________________________
R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Received on Mon 14 Mar 2011 - 20:53:18 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Mon 14 Mar 2011 - 21:10:22 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive