Select the values of a range of layers, as specified by cell values in another SpatRaster
Useful links