I am getting this error when working with very large rasters.
h.dist <- gdistance::transition(DEM, transitionFunction = function(x){1}, directions = 8, symm = TRUE)
h.dist <- gdistance::geoCorrection(h.dist, scl = FALSE)
adj <- raster::adjacent(DEM, cells = 1:ncell(DEM), pairs = TRUE, directions = 8)
h.dist[adj] <- 1/h.dist[adj]
The error comes from the last line:
h.dist[adj] <- 1/h.dist[adj]
If I do something like:
h.dist[tail(adj)] <- 1/h.dist[tail(adj)]
or
h.dist[adj[1:10,]] <- 1/h.dist[adj[1:10,]]
It works fine. The adj matrix has 1164557166 rows, so I don't know whether there is a hard limit on the indexing that can be handled by sparse matrices?
I guess I can do a for loop and process it in chunks, would that work?