A SpatRaster with as many layers as there are classes.
Pixels matching the class of interest are set to 1, backround values by default are set to 0 (see background argument)
Arguments
img
SpatRaster or integer/numeric vector containing multiple classes
classes
integer: vector of classes which should be extracted
background
integer: background value (default = 0)
foreground
integer: foreground value (default = 1)
na.rm
logical: if TRUE, NAs will be coerced to the background value.
...
further arguments passed to writeRaster. Ignored if img is not a SpatRaster, but a numeric/integer vector or matrix