The raster package has the sometimes problematic behavior of leaving temporary files after the R object has been removed.
This function first checks if a temporary file exists on disk and removes it.
Usage
rmRaster(x, verbose = FALSE)
Arguments
x
a raster* object to be removed
verbose
logical indicating whether to print verbose messages