Great suggestions, thanks ! Point 2 seems particularly “promising”.
I’ll add my 2 cents: an alternative solution I find useful to avoid accumulation of large rasters is to explicitly specify to save to a “tiff” file (even temporary if I don’t need it later) whenever possible. Most
raster functions (e.g.,
mask, etc.) allow this through the
filename argument, and results are still accessible in the “usual” ways.
Since this allows also to specify compression options, using for example:
filename = tempfile(fileext = ".tif"),
options = "COMPRESS=LZW"
allows to save a lot of space thanks to the efficiency of TIF compression, in particular for categorical data or data containing a lot of NAs (explicitly setting the datatype when possible, thus avoiding the “auto” saving as FLT4S can also help).
This has however some consequences on performance due to compressing/decompressing (I’d be curious to see some benchmarks concerning trade-offs between reduction in speed due to comp/decomp and (possible) gains due to reduced time needed to read/write on/to disk).