### SpatRaster
s <- rast(system.file("ex/logo.tif", package="terra"))
subset(s, 2:3)
subset(s, c(3,2,3,1))
#equivalent to
s[[ c(3,2,3,1) ]]
s[[c("red", "green")]]
s$red
# expression based (partial) matching of names with single brackets
s["re"]
s["^re"]
# not with double brackets
# s[["re"]]
### SpatVector
v <- vect(system.file("ex/lux.shp", package="terra"))
subset(v, v$NAME_1 == "Diekirch", c("NAME_1", "NAME_2"))
subset(v, NAME_1 == "Diekirch", c(NAME_1, NAME_2), NSE=TRUE)
# or like this
v[2:3,]
v[1:2, 2:3]
v[1:2, c("NAME_1", "NAME_2")]
Run the code above in your browser using DataLab