[R-sig-Geo] Managing temporary files created when using the Raster package

Jonathan Greenberg jgrn at illinois.edu
Sun Mar 23 23:58:50 CET 2014


Julie:

Why not just build a ?file.remove into your script?  Also, most raster
functions allow you to explicitly set a filename (see e.g. ?calc -->
the filename= parameter), rather than letting it generate a random
filename -- this would likely make it easier for you to figure out the
appropriate file to delete.

--j

On Sun, Mar 23, 2014 at 4:44 PM, Julie Lee-Yaw <julleeyaw at yahoo.ca> wrote:
> Hi
>
> I am doing a lot of raster calculations repeatedly (in a loop of sorts). As might be expected, this process is generating a lot of temporary files and filing up my hard drive before my script finishes. The first step in my script is to stack a set of very large rasters. This stack is then the input for the function that I'm using (e.g. the loop). Can I add in a line in my loop (e.g. removeTmpFiles) to delete temporary files created during the loop without ruining the integrity of the raster stack?
>
> For example:
>
> files<-list.files(pattern=".tif")
> myStack<-stack(files)
>
> myFunction<-function(x, rasterStack, y, z){
> # several calculations using the raster stack and x, y, z
> # non-raster results from the calculations get saved to file using write.csv()
> removeTmpFiles(h=0) # remove temp. raster files from disk???
> }
>
> lapply(x=list_of_x_values, myFunction, rasterStack=myStack, y=something, z=somethingelse)
>
> Is the removeTmpFiles line appropriate here?
>
> Thanks for the help!
>         [[alternative HTML version deleted]]
>
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>



-- 
Jonathan A. Greenberg, PhD
Assistant Professor
Global Environmental Analysis and Remote Sensing (GEARS) Laboratory
Department of Geography and Geographic Information Science
University of Illinois at Urbana-Champaign
259 Computing Applications Building, MC-150
605 East Springfield Avenue
Champaign, IL  61820-6371
Phone: 217-300-1924
http://www.geog.illinois.edu/~jgrn/
AIM: jgrn307, MSN: jgrn307 at hotmail.com, Gchat: jgrn307, Skype: jgrn3007



More information about the R-sig-Geo mailing list