1

I have thousand files and each one contains a .shp. The names of my files are file_sh1,file_sh2,..,file_sh5000 and the names of the .shps are the same.I am trying to read them in R and then export them (all .shps in one file) but I get the error "Error in getinfo.shape(fn) : Error opening SHP file".

my code so far:

fle=list()
for (i in 1:5000){
  fle[[i]]=readShapeSpatial("fle/file_sh",i,"/file_sh",i,".shp")
} 

How can I read the .shps from the files and export them in one?

geo_dd
  • 283
  • 1
  • 5
  • 22

1 Answers1

1

Don't forget to paste your string:

fle=list()
for (i in 1:5000){
  fle[[i]]=readShapeSpatial(paste0("fle/file_sh",i,"/file_sh",i,".shp"))
} 

Example of paste0:

> i=1
> paste0("fle/file_sh",i,"/file_sh",i,".shp")
[1] "fle/file_sh1/file_sh1.shp"

For the second part of your question, see here or here or here.

Florian
  • 24,425
  • 4
  • 49
  • 80
  • Thank you @Florian. That was a stupid mistake. As for the second part of my question, I did not want to merge my .shps but to save them in one folder instead of 5000. Thanks a lot! – geo_dd Jul 25 '17 at 06:56