library(terra)
mtx = matrix(0, 33, 33)
r = rast(mtx)
ext(r) = c(0, 10, 0, 10)
patchSize = 500
rr = makePatch(r, patchSize, rast=TRUE)
plot(rr)
## Create a patch with value 3, starting from the centre cell
mtx = matrix(0, 33, 33)
r = rast(mtx)
ext(r) = c(0, 10, 0, 10)
newVal = 3
centre = 545
cells = makePatch(r, patchSize, centre)
values(r) = newVal
plot(r)
## Now create a new patch with value 10 and size 100 inside the existing patch
rr = makePatch(r, 100, bgr=newVal, rast=TRUE, val=10)
plot(rr)
Run the code above in your browser using DataLab