geo_dd geo_dd - 3 years ago 372
R Question

Error in getinfo.shape(fn) : Error opening SHP file in R

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?

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download