I'm using the raster
(2.1-49) package in R
(3.0.1) to read in many rasters, calculate some statistics and store the results. Some of the rasters are too big to store in memory so are written as a temporary file in the folder different to the one indicated by tempdir()
. The problem is that in reality I have over 5000 rasters, and the temporary files fill up my hard drive before the script finishes running. I would like to overwrite the same temporary file on each iteration of the loop. My code looks something like this:
require(raster)
names<- seq(1:5000)
for (i in 1:5000)
{
r <- raster(paste("rast_",names[i],".tif"),sep="")
#Stats Code#
}
Adding filename="C:/temp",overwrite=T
to the raster
function line of code did not work. However, these two additional options work with the rasterize
function from the same package...
Is there a way to set a single temporary file that can be overwritten for the raster
function?
Any help much appreciated.