5.14 Extent

elev = rast(system.file("raster/elev.tif", package = "spData"))
clip = rast(xmin = 0.9, xmax = 1.8, ymin = -0.45, ymax = 0.45,
            resolution = 0.3, vals = rep(1, 9))
elev[clip, drop = FALSE]
## class       : SpatRaster 
## dimensions  : 2, 1, 1  (nrow, ncol, nlyr)
## resolution  : 0.5, 0.5  (x, y)
## extent      : 1, 1.5, -0.5, 0.5  (xmin, xmax, ymin, ymax)
## coord. ref. : lon/lat WGS 84 (EPSG:4326) 
## source(s)   : memory
## name        : elev 
## min value   :   18 
## max value   :   24
plot(elev)

Following code adds one row and two columns to each side of the raster while setting all new values to NA

elev_2 = extend(elev, c(1, 2))

plot(elev_2)

# PRODUCES ERROR: extends do not match
elev_3 = elev + elev_2
# correct implementation
elev_4 = extend(elev, elev_2)