I am looking for a way to improve the speed and lower the memory-usage of the following lines:
export <- raster(paste0(catch_dir,'/export_streams.rst'))
catchm_polyg <- readOGR(dsn = catch_dir, layer = 'catchment')
Model_10 <- extract(export, catchm_polyg, fun = sum, na.rm = TRUE )
This gives me the sum of all values from export_streams.rst, with catchm_polyg as an extent.
I want to do this a lot of times for different input-data. Therefor the code is part of a function
, which is then used in a foreach
loop. That all works fine to a certain degree. The code doesn't work with larger input-data though, as I apparently don't have enough memory (32gb, 64bit R version). Also the calculation time is very high. Any suggestions on how to improve the code?