### SpatRaster
s <- rast(system.file("ex/logo.tif", package="terra"))
s[[ 1:2 ]]
s[[c("red", "green")]]
# expression based (partial) matching of names with single brackets
s["re"]
s["^re"]
# does not with double brackets
# s[["re"]]
### SpatVector
v <- vect(system.file("ex/lux.shp", package="terra"))
v[[2:3]]
# to keep the geometry use
v[,2:3]
Run the code above in your browser using DataLab