1

I'm using the raster package function projectRaster to match a high resolution raster (~700Mb) to a lower resolution one (~1Mb). Unfortunately, I run into this error;

Error: vector memory exhausted (limit reached?)

Based on this thread, it looks like it is possible to extend R's memory. However, I would like to avoid messing around with this if possible. I was wondering if it might be an option to divide the higher resolution raster into smaller components and do the reprojection piecemeal? Or is that more hassle than it is worth, and I should investigate the memory increase option? Or even better, is there a workaround that avoids this issue altogether? I can't be the only person working with moderately large raster files...

EcologyTom
  • 2,344
  • 2
  • 27
  • 38

1 Answers1

2

You should be able to tell raster to use less memory. Perhaps set memfrac to lower value with rasterOptions

rasterOptions()
rasterOptions(memfrac=.3)

Also, it is probably a good idea to first aggregate the high resolution raster so that the cell size is about half that of the low resolution raster before using projectRaster

Robert Hijmans
  • 40,301
  • 4
  • 55
  • 63
  • Thanks! I wasn't aware of `rasterOptions`. Just reducing the `memfrac` was enough to get it to work. As to your second suggestion; will I lose accuracy by having two resampling steps? (i.e. both the `aggregate` step and the `projectRaster`) – EcologyTom May 12 '19 at 18:16
  • I think it would be more accurate, as long as you do not over-aggregate. That is because projectRaster will query the old raster with the center of new cells; the old cells may be a poor representation if the resolution difference is large. – Robert Hijmans May 12 '19 at 22:03