I have a list of cells within a raster for which I would like to change the value of the cells (while leaving all other cells alone). I have copied some test (reproducible) code below that I have managed to get working. It generates a test raster, and, for the cells defined in vals, changes the cells to a value of 50.
# My List of Cells That Require Changing
vals<-c(2,4,6,10,15,27)
#Example Raster
r <- raster(ncol=6, nrow=6)
r[] <- 1:ncell(r)
plot(r)
#Change Cell Values
r[r%in%c(vals)] <- 50
plot(r)
So far, so good. However, when I apply the same code to my real life data I cannot change the cell values. The code runs absolutely fine (no error messages at all) but the cell values simply don't change.
My first question is whether anyone else has come across this issue before? My second question is: what's the best way of me providing my real-world example to the StackOverflow community so that maybe someone could help me troubleshoot the issue? I fear that without using my dataset, this issue will remain unresolved. I have read that using r[r%in%c(vals)] <- 50 can be unstable memory-wise for large rasters but I'm not sure this is the case with my example (my raster is an image of Jamaica and only contains 4185 cells and when running the code, I haven't noticed any spikes in RAM usage).
Any assistance you can provide will be greatly appreciated.