I've been getting an error in a script that iterates over some text files in a directory, does some data manipulation and writes to a ESRI shapefile using writeOGR from the rgdal package in R. I keep getting an error after a certain number of files are written (appears to be about 43-44 individual files, or ~14 complete shapefiles, as each shapefile creates a number of files).
The error is usually something like
GDAL Error 4: Unable to open ./test_8.shp or ./test_8.SHP
Additionally, after the script has crashed I get an error like
cannot open file 'file_test.R': Too many open files
When I try to read or do anything with another file.
showConnections
does not show any open files at this point.
Here is some code that reproduces the problem:
library(gstat)
library(rgdal)
data(meuse)
coordinates(meuse) = ~x + y
for (i in 1:50){
writeOGR(meuse,'.',paste('test',i,sep="_"),driver="ESRI Shapefile")
}
I'm using R 2.12.2 on OSX. Error happens on both 64 bit and 32 bit versions.
Your code worked for me on Ubuntu 11.04 and R 2.13, might be worth also to try writeSpatialShape
from the maptools
package.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With